| peek_at | R Documentation |
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.
peek_at(.x, ...)
## S3 method for class 'Container'
peek_at(.x, ..., .default = NULL)
## S3 method for class 'dict.table'
peek_at(.x, ..., .default = NULL)
.x |
an |
... |
indices of elements to be extracted |
.default |
value to be returned if peeked value does not exist. |
peek_at tries to access specific values.
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.
at() for strict element extraction
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.