get_val2 | R Documentation |
Get value or return default if invalid
get_val2(x, key = NA, default = NULL, na = FALSE, min_len = 1L, ...)
x |
a list, or environment, or just any R object |
key |
the name to obtain from |
default |
default value if |
na, min_len, ... |
passed to |
values of the keys or default is invalid
x <- list(a=1, b = NA, c = character(0))
# ------------------------ Basic usage ------------------------
# no key, returns x if x is valid
get_val2(x)
get_val2(x, 'a', default = 'invalid')
# get 'b', NA is not filtered out
get_val2(x, 'b', default = 'invalid')
# get 'b', NA is considered invalid
get_val2(x, 'b', default = 'invalid', na = TRUE)
# get 'c', length 0 is allowed
get_val2(x, 'c', default = 'invalid', min_len = 0)
# length 0 is forbidden
get_val2(x, 'c', default = 'invalid', min_len = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.