assert_set_equal | R Documentation |
This function checks that x
and y
contain exactly the same elements, ignoring order and duplicates.
assert_set_equal(x, y, msg = NULL, call = rlang::caller_env(), arg_name = NULL)
x |
A vector to compare |
y |
Another vector to compare with |
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
and y
contain all the same elements (ignoring order and duplicates), otherwise throws an error.
# Passes because elements are the same, order doesn't matter
assert_set_equal(c(1, 2, 3), c(3, 2, 1))
# Passes because elements are identical
assert_set_equal(c("A", "B", "C"), c("C", "A", "B"))
try({
# Throws error because elements are not identical
assert_set_equal(c(1, 2, 3), c(1, 2))
# Throws error because elements differ
assert_set_equal(c("A", "B"), c("A", "B", "C"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.