Search for old name and replace it by new name. If either the old name does not exist or the name would result in a name-clash with an already existing name, an error is signaled.

rename(.x, old, new)

ref_rename(.x, old, new)

# S3 method for Container
rename(.x, old, new)

# S3 method for dict.table
rename(.x, old, new)

# S3 method for dict.table
ref_rename(.x, old, new)

# S3 method for default
rename(.x, old, new)

Arguments

.x

dict.table object

old

character old name

new

character new name

Value

For standard R vectors renames old to new and returns the renamed vector.

For Container, an object of class Container (or one of the respective derived classes).

For dict.table renames key old to new in place (i.e. by reference) and invisibly returns the dict.table() object.

Details

The passed old and new names can be vectors but always must have the same length and must be unique to prevent double-renaming.

rename uses copy semantics while ref_rename works by reference, that is, it renames elements in place.

Examples


# Container
co = container(a = 1, b = 2, 3)
rename(co, c("a", "b"), c("a1", "y"))
#> [a1 = 1, y = 2, 3]
print(co)
#> [a = 1, b = 2, 3]
ref_rename(co, c("a", "b"), c("a1", "y"))
#> [a1 = 1, y = 2, 3]
print(co)
#> [a1 = 1, y = 2, 3]

# dict.table
dit = dict.table(a = 1, b = 2, c = 3)
rename(dit, c("a", "b"), c("a1", "y"))
#> <dict.table> with 1 row and 3 columns
#>    a1 y c
#> 1:  1 2 3
print(dit)
#> <dict.table> with 1 row and 3 columns
#>    a b c
#> 1: 1 2 3
ref_rename(dit, c("a", "b"), c("a1", "y"))
print(dit)
#> <dict.table> with 1 row and 3 columns
#>    a1 y c
#> 1:  1 2 3