assert_subset | R Documentation |
This function checks that x
is a subset of y
assert_subset(x, y, msg = NULL, call = rlang::caller_env(), arg_name = NULL)
x |
A vector to check |
y |
the acceptable values that x can take |
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 subset of y
, otherwise throws an error
try({
assert_subset(1:3, 1:5) # Passes
assert_subset(c("A", "B", "C"), c("A", "B")) # Throws error since "C" is not present in first vector
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.