at2 {container} | R Documentation |
Extract Single Elements Safely
Description
Extracts the value of a Container at the given index. If the 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. Extract value at index. If index is invalid or not found, 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.
Usage
at2(x, ...)
## S3 method for class 'Container'
at2(x, index, ...)
## S3 method for class 'dict.table'
at2(x, index, ...)
Arguments
x |
an |
... |
other arguments passed to or from methods. |
index |
|
Value
For Container
, returns the value at the given index.
For dict.table
, returns the column at the given index
or signals
an error if not found.
See Also
peek_at2()
for less strict extraction
Examples
# Container
co = container(a = 1, 2, b = 3, 4)
at2(co, 1)
at2(co, "a")
at2(co, 2)
try(at2(co, "x")) # index 'x' not found
try(at2(co, 5)) # index 5 exceeds length of Container
# Dict
d = dict(a = 1, b = 3)
at2(d, 1)
at2(d, "a")
at2(d, 2)
try(at2(d, "x")) # index 'x' not found
try(at2(d, 5)) # index 5 exceeds length of Dict
# dict.table
dit = dict.table(a = 1:3, b = 4:6)
at2(dit, 1)
at2(dit, "a")
at2(dit, 2)
try(at2(dit, "x")) # index 'x' not found
try(at2(dit, 5)) # index 5 exceeds length of dict.table