visualizeR/R/internals.R

39 lines
961 B
R

# not in
#' Not In Operator
#'
#' A negation of the `%in%` operator that tests if elements of `a` are not in `b`.
#'
#' @param a Vector or value to test
#' @param b Vector to test against
#'
#' @return Logical vector with TRUE for elements of `a` that are not in `b`
`%notin%` <- function(a, b) {
!(a %in% b)
}
# not all in
#' Not All In Operator
#'
#' Tests if not all elements of `a` are contained in `b`.
#'
#' @param a Vector to test
#' @param b Vector to test against
#'
#' @return TRUE if at least one element of `a` is not in `b`, otherwise FALSE
`%notallin%` <- function(a, b) {
!(all(a %in% b))
}
# infix for null replacement
#' @importFrom rlang `%||%`
#' If Null Replace Operator
#'
#' An alias for the `%||%` operator that returns `a` if it's not NULL, otherwise returns `b`.
#'
#' @param a First value to test
#' @param b Value to use if `a` is NULL
#'
#' @return `a` if not NULL, otherwise `b`
`%ifnullrep%` <- function(a, b) {
a %||% b
}