| rename {container} | R Documentation |
Rename Elements Safely
Description
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)
Arguments
.x |
|
old |
|
new |
|
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.
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.
Examples
# Container
co = container(a = 1, b = 2, 3)
rename(co, c("a", "b"), c("a1", "y"))
print(co)
ref_rename(co, c("a", "b"), c("a1", "y"))
print(co)
# dict.table
dit = dict.table(a = 1, b = 2, c = 3)
rename(dit, c("a", "b"), c("a1", "y"))
print(dit)
ref_rename(dit, c("a", "b"), c("a1", "y"))
print(dit)
[Package container version 1.0.4 Index]