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.
Usage
rename(.x, old, new)
ref_rename(.x, old, new)
# S3 method for class 'Container'
rename(.x, old, new)
# S3 method for class 'dict.table'
rename(.x, old, new)
# S3 method for class 'dict.table'
ref_rename(.x, old, new)
# Default S3 method
rename(.x, old, new)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
#> <num> <num> <num>
#> 1: 1 2 3
print(dit)
#> <dict.table> with 1 row and 3 columns
#> a b c
#> <num> <num> <num>
#> 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
#> <num> <num> <num>
#> 1: 1 2 3
