| rename | R Documentation |
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 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)
.x |
|
old |
|
new |
|
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.
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.