Data checks - Check if object is in (and/or not in) a set
is_matching_set.RdThis function checks if an object is in a set of values, and optionally if it is not in another set of values. It can check if all, any, or only the values are in the set.
Arguments
- x
[
atomic|list()] An atomic vector or list to test.- yes, no
[
atomic|list()|NULL] A set of values thatxshould be in, and not be in, respectively. IfNULL, this check is ignored.- mode
[
"all"|"any"|"only"] The mode of the check:"all"for all values inxmust be inyes,"any"for at least one value inxmust be inyes, and"only"for all values inxmust be inyesand all values inyesmust be inx.
Examples
x <- c(5, 7, 5, 9, 9)
# Default mode checks if all values in `x` are in `yes` and not in `no`:
is_matching_set(x, yes = 1:10) #> TRUE
#> [1] TRUE
is_matching_set(x, yes = 1:8) #> FALSE
#> [1] FALSE
is_matching_set(x, yes = 1:10, no = 5) #> FALSE
#> [1] FALSE
# Mode `any` passes even if there are values in `x` that are not in `yes`:
is_matching_set(x, yes = 1:6, mode = "any") #> TRUE
#> [1] TRUE
# For mode `only`, all values in `x` must be in `yes` and vice versa:
is_matching_set(x, yes = 1:10, mode = "only") #> FALSE
#> [1] FALSE
is_matching_set(x, yes = c(5, 7, 9), mode = "only") #> TRUE
#> [1] TRUE
# `yes` can be NULL to test only `no` (independent of mode):
is_matching_set(x, no = 11) #> TRUE
#> [1] TRUE
is_matching_set(x) #> TRUE
#> [1] TRUE