R/out.R

#' Outside Subset
#'
#' Operators for checking if value is outside a given interval or subset.
#'
#' Parenthesss of each operator define how the subset is specified:\cr
#' \code{\%out\{\}\%} - lists all elements of the subset\cr
#' \code{\%out[]\%} - subset specified as an closed interval\cr
#' \code{\%out()\%} - subset specified as a open interval\cr
#' \code{\%out(]\%} - interval that is open on the left and closed on the right\cr
#' \code{\%out[)\%} - interval that is closed on the left and open on the right\cr\cr
#'
#' \code{\%out\%} is provided as a convenient complement for \code{\%in\%}.
#'
#' The operations using intervals are a convenient short hand for\cr\code{!(x > interval[1] & x < interval[2])}.
#'
#' The idea for function names is taken from the package DescTools by Andri Signorell.
#'
#' @param x vector or array of values to be matched.
#' @param subset vector or list of values to be matched against.
#' @param interval vector with two elements defining an interval range.
#'
#' @return a logical vector or an array of the same dimensions as \code{x}
#' indicating if each value of \code{x} is outside the defined subset.
#'
#' @seealso \code{\%in\%}, \code{\%in{}\%}, \code{\link[DescTools]{\%[]\%}}
#'
#' @examples
#'   c("a", "b", "Z") %out{}% letters
#'
#'   iris %out{}% "setosa"
#'
#'   1:10 %ouout c(2,5)
#'
#' @name out
#' @author Karolis Koncevičius
#' @export
`%out%` <- function(x, subset) {
  !(x %in% subset)
}

#' @rdname out
#' @export
`%out{}%` <- function(x, subset) {
  !(x %in{}% subset)
}

#' @rdname out
#' @export
`%out[]%` <- function(x, interval) {
  !(x %in[]% interval)
}

#' @rdname out
#' @export
`%out()%` <- function(x, interval) {
  !(x %in()% interval)
}

#' @rdname out
#' @export
`%out(]%` <- function(x, interval) {
  !(x %in(]% interval)
}

#' @rdname out
#' @export
`%out[)%` <- function(x, interval) {
  !(x %in[)% interval)
}
KKPMW/infixer documentation built on May 7, 2019, 6:04 a.m.