Extract parts of a Container at given indices. If an index is invalid, an error is signaled. If given as a string, the element matching the name is returned. If there are two or more identical names, the value of the first match (i.e. leftmost element) is returned. Indices can be letters or numbers, or both at the same time.

at(.x, ...)

# S3 method for Container
at(.x, ...)

# S3 method for dict.table
at(.x, ...)

Arguments

.x

an R object of the respective class.

...

indices of elements to be extracted

Value

For Container, returns the values at the given indidces.

For dict.table, returns the columns at the given indices.

See also

peek_at() for less strict extraction

Examples


# Container
co = container(a = 1, 2, b = 3, 4)
at(co, 1:3)
#> [a = 1, 2, b = 3]
at(co, "a", "b", 2)
#> [a = 1, b = 3, 2]
try(at(co, "x"))     # index 'x' not found
#> Error : index 'x' not found
try(at(co, 1:10))    # index 5 exceeds length of Container
#> Error : index 5 exceeds length of Container, which is 4
# Dict
d = dict(a = 1, b = 3)
at(d, 1:2)
#> {a = 1, b = 3}
at(d, "a", 2)
#> {a = 1, b = 3}
try(at(d, "x"))      # index 'x' not found
#> Error : index 'x' not found
try(at(d, 1:3))      # index 5 exceeds length of Dict
#> Error : index 3 exceeds length of Dict, which is 2

# dict.table
dit = dict.table(a = 1:3, b = 4:6)
at(dit, "a")
#> <dict.table> with 3 rows and 1 column
#>    a
#> 1: 1
#> 2: 2
#> 3: 3
at(dit, 2)
#> <dict.table> with 3 rows and 1 column
#>    b
#> 1: 4
#> 2: 5
#> 3: 6
at(dit, "a", 2)
#> <dict.table> with 3 rows and 2 columns
#>    a b
#> 1: 1 4
#> 2: 2 5
#> 3: 3 6
try(at(dit, "x"))     # index 'x' not found
#> Error : index 'x' not found
try(at(dit, 1:3))     # index 3 exceeds length of dict.table
#> Error : index 3 exceeds length of dict.table, which is 2