R/not_in.R

Defines functions `%!in%`

#' Negation of \%in\%
#'
#' Provides a "not in" like in Python by negating \code{\%in\%}.
#'
#' In my opinion this is prettier and more readable than using \code{!x \%in\%
#' y}. By the way, this notation works without parentheses because \code{\%in\%}
#' takes precedence before \code{!}, see \link[base]{Syntax}.
#'
#' @param a The values to be matched.
#' @param b The values to be matched against.
#'
#' @return The negated output of \code{\link[base:match]{\%in\%}}.
#'
#' @examples
#' 42 %!in% 1:10  # TRUE
#'
#' @name not_in
#' @export
`%!in%` <- function(a, b) {
    !a %in% b
}

# A note on the roxygen comments: The help name must not contain an exclamation
# mark. This is why I wrote "@name not_in". The correct title of the function,
# however, is still included as an alias in the rd file.

# I could define this by writing
# `%!in%` <- Negate(`%in%`)
# but then the Usage section in the help page generated by roxygen would be
# neither pretty nor helpful.
BastiHz/BastiHzR documentation built on March 24, 2021, 1:48 p.m.