# Define example vectors:
ab <- c("a", "b")
abc <- c("a", "b", "c")
abcde <- c("a", "b", "c", "d", "e")
# `is_subset_of()` tests if a vector is
# completely covered by another one:
abc %>% is_subset_of(ab)
abc %>% is_subset_of(abc)
abc %>% is_subset_of(abcde)
# To the contrary, `is_superset_of()` tests if the
# first vector completely covers the second one:
abc %>% is_superset_of(ab)
abc %>% is_superset_of(abc)
abc %>% is_superset_of(abcde)
# `is_equal_set()` tests both of the above --
# i.e., if both vectors have exactly the
# same values:
abc %>% is_equal_set(ab)
abc %>% is_equal_set(abc)
abc %>% is_equal_set(abcde)
# Each of the three functions has a `*_vals()` variant
# that doesn't take a second vector like the first
# one, but any number of other arguments. These are
# jointly treated like the elements of the second
# vector in the basic functions:
abc %>% is_subset_of_vals("a", "b")
abc %>% is_subset_of_vals("a", "b", "c")
abc %>% is_subset_of_vals("a", "b", "c", "d", "e")
# (... and likewise for supersets and equal sets.)
Run the code above in your browser using DataLab