Add elements to container-like objects.
Usage
add(.x, ...)
ref_add(.x, ...)
# S3 method for class 'Container'
add(.x, ...)
# S3 method for class 'Container'
ref_add(.x, ...)
# S3 method for class 'Dict'
add(.x, ...)
# S3 method for class 'Dict'
ref_add(.x, ...)
# S3 method for class 'dict.table'
add(.x, ...)
# S3 method for class 'dict.table'
ref_add(.x, ...)
Value
For Container, an object of class Container (or one of the respective derived classes).
For dict.table an object of class dict.table.
Note
While add uses copy semantics ref_add works by reference.
If .x
is a Container, Set or Deque object, the elements being added
can (but must not) be named.
If .x
is a Dict or dict.table object,
all elements must be of the form key = value
.
If one of the keys already exists, an error is given.
Examples
co = container(1)
add(co, 1, b = 2, c = container(1:3))
#> [1, 1, b = 2, c = [(1L 2L 3L)]]
s = setnew(1)
add(s, 1, 1, b = 2, "1", co = container(1, 1))
#> {1, b = 2, "1", co = [1, 1]}
d = dict(a = 1)
add(d, b = 2, co = container(1:3))
#> {a = 1, b = 2, co = [(1L 2L 3L)]}
try(add(d, a = 7:9)) # key 'a' already in Dict
#> Error : name 'a' exists already
dit = dict.table(a = 1:3)
add(dit, b = 3:1, d = 4:6)
#> <dict.table> with 3 rows and 3 columns
#> a b d
#> <int> <int> <int>
#> 1: 1 3 4
#> 2: 2 2 5
#> 3: 3 1 6
try(add(dit, a = 7:9)) # column 'a' already exists
#> Error : name 'a' exists already
dit = dict.table(a = 1:3)
add(dit, b = 3:1, d = 4:6)
#> <dict.table> with 3 rows and 3 columns
#> a b d
#> <int> <int> <int>
#> 1: 1 3 4
#> 2: 2 2 5
#> 3: 3 1 6
try(add(dit, a = 7:9)) # column 'a' already exists
#> Error : name 'a' exists already