peek_at {container} | R Documentation |
Peek at Indices
Description
Try to access elements and return default values if not found.
In contrast to [at()]
, this function provides a less stricter element
access, that is, it remains valid even if elements don't exist.
Usage
peek_at(.x, ...)
## S3 method for class 'Container'
peek_at(.x, ..., .default = NULL)
## S3 method for class 'dict.table'
peek_at(.x, ..., .default = NULL)
Arguments
.x |
an |
... |
indices of elements to be extracted |
.default |
value to be returned if peeked value does not exist. |
Details
peek_at
tries to access specific values.
Value
For Container
, returns the value at the given indices or (if not
found) the given default value.
For dict.table
, returns the columns at the given indices or (if not
found) columns with the given default value.
See Also
at()
for strict element extraction
Examples
# Container
co = container(a = 1, 2, b = 3, 4)
peek_at(co, 1)
peek_at(co, "a")
peek_at(co, "x")
peek_at(co, "x", .default = 0)
peek_at(co, "a", "x", 2, 9, .default = -1)
# Dict
d = dict(a = 1, b = 1:3)
peek_at(d, "b")
peek_at(d, "x")
peek_at(d, "x", .default = 4:7)
# dict.table
dit = dict.table(a = 1:3, b = 4:6)
peek_at(dit, "a")
peek_at(dit, 1)
peek_at(dit, 3)
peek_at(dit, "x")
peek_at(dit, "x", .default = 0)
peek_at(dit, "a", "x", .default = 0)
[Package container version 1.0.4 Index]