Description Usage Arguments Details Value Examples
Check that the arguments passed for a parameter are in a set of valid values, and throw a warning & return a default value if validation fails.
1 |
arg |
The parameter name to validate values for (character scalar). |
name |
The name of the current loop variable (character scalar). |
val |
The value of the current loop variable. |
validVals |
A vector/list of the valid values that the parameter can take. |
silent |
Whether to silence the warning that usually appears when validation fails (boolean scalar). |
This is an internal function meant to be called unconditionally inside a loop.
It will only perform validation if arg == name
.
If ! val %in% validVals
, validVals[1]
will be returned, else val
.
1 2 3 4 5 6 7 8 9 10 11 | # Valid value, "apple" is returned
check_arg("fruit", "fruit", "apple", c("apple", "banana", "cherry"))
# Invalid value, "banana" is returned
check_arg("fruit", "fruit", "apple", c("banana", "cherry"), silent = TRUE)
# Throws a warning
## Not run:
check_arg("fruit", "fruit", "apple", c("banana", "cherry"))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.