assert_one_of | R Documentation |
Assert x
is one of the values of y
.
assert_one_of(x, y, msg = NULL, call = rlang::caller_env(), arg_name = NULL)
x |
A scalar value to check |
y |
A vector of acceptable values that |
msg |
The error message thrown if the assertion fails (string) |
call |
Only relevant when pooling assertions into multi-assertion helper functions. See cli_abort for details. |
arg_name |
Advanced use only. Name of the argument passed (default: NULL, will automatically extract arg_name). |
Returns invisible(TRUE) if x
is a scalar and is one of the values in y
, otherwise throws an error
assert_one_of(3, 1:5) # Passes because 3 is in 1:5
assert_one_of("A", c("A", "B", "C")) # Passes because "A" is in the vector
try({
assert_one_of("D", c("A", "B", "C")) # Throws error because "D" is not in the vector
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.