R/is.subset.R

#' Check subset inclusion
#' 
#' Determines whether one vector contains all the elements of another.
#' 
#' Determines whether or not every element of \code{x} is also found in
#' \code{y}. Returns \code{TRUE} if so, and \code{FALSE} if not.
#' 
#' @aliases is.subset %subof%
#' @param x vector.
#' @param y vector.
#' @return A logical of length 1.
#' @author Robin Evans
#' @seealso \code{\link{setmatch}}.
#' @keywords arith
#' @examples
#' 
#' is.subset(1:2, 1:3)
#' is.subset(1:2, 2:3)
#' 1:2 %subof% 1:3
#' 1:2 %subof% 2:3
#' 
#' @export is.subset
is.subset <-
function (x, y) 
{
    return(all(x %in% y))
}

#' @describeIn is.subset operator version
#' @export
`%subof%` <-
  function (x, y) 
  {
    is.subset(x, y)
  }

Try the rje package in your browser

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

rje documentation built on Nov. 12, 2022, 9:06 a.m.