peek_at2 | R Documentation |
Try to access element and return some default value if not found.
In contrast to [at2()]
, this function provides a less stricter element
access, that is, it remains valid even if peeked elements don't exist.
peek_at2(x, index, default = NULL) ## S3 method for class 'Container' peek_at2(x, index, default = NULL) ## S3 method for class 'dict.table' peek_at2(x, index, default = NULL)
x |
an |
index |
|
default |
value to be returned if peeked value does not exist. |
For Container
, returns the value at the given index or (if not
found) the given default value.
For dict.table
, returns the column named index
if it exist
otherwise the given default
value. If the default length does not match
the number of rows, it is recycled accordingly and a warning is given,
unless the default value has a length of 1, in which case recycling is
done silently.
at2()
for strict element extraction
# Container co = container(a = 1, 2, b = 3, 4) peek_at2(co, 1) peek_at2(co, "a") peek_at2(co, "x") peek_at2(co, "x", default = 0) # Dict d = dict(a = 1, b = 1:3) peek_at2(d, "b") peek_at2(d, "x") peek_at2(d, "x", default = 4:7) # dict.table dit = dict.table(a = 1:3, b = 4:6) peek_at2(dit, "a") peek_at2(dit, 1) peek_at2(dit, 3) peek_at2(dit, 3, default = 9) peek_at2(dit, "x") peek_at2(dit, "x", default = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.