R/is_subset.R

Defines functions is_subset

Documented in is_subset

#' Determine whether the first vector is a subset of the second vector
#'
#' @param x the first vector
#' @param y the second vector
#' @return `TRUE` if `x` is a subset of `y`, or `FALSE` otherwise. `x` is
#'      considered a subset of `y` if all elements of `x` are also in `y`,
#'      i.e., if `setdiff(x, y)` is a vector of length 0.
#' @author Michal Burda
#' @export
is_subset <- function(x, y) {
    .must_be_vector(x, null = TRUE)
    .must_be_vector(y, null = TRUE)

    length(setdiff(x, y)) == 0L
}

Try the nuggets package in your browser

Any scripts or data that you put into this service are public.

nuggets documentation built on April 3, 2025, 8:07 p.m.