% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/infix.r
\name{suppr-infix}
\alias{suppr-infix}
\alias{\%''\%}
\alias{\%""\%}
\alias{\%!||\%}
\alias{\%0\%}
\alias{\%allin\%}
\alias{\%anyin\%}
\alias{\%nonein\%}
\alias{\%onein\%}
\alias{\%notin\%}
\title{Infix Operator Helpers}
\usage{
lhs \%''\% rhs

lhs \%""\% rhs

lhs \%!||\% rhs

lhs \%0\% rhs

x \%allin\% table

x \%anyin\% table

x \%nonein\% table

x \%onein\% table

x \%notin\% table
}
\arguments{
\item{lhs}{left-hand side object.}

\item{rhs}{right-hand side object.}

\item{x}{\link{vector} or \code{NULL}: the values to be matched.
\link{Long vectors} are supported.}

\item{table}{vector or \code{NULL}: the values to be matched against.
\link{Long vectors} are not supported.}
}
\value{
For the non-\verb{\%*in\%} operators, either the left-hand side or
right-hand side, depending on the result of the operator.

For \verb{\%allin\%}, \verb{\%anyin\%}, \verb{\%nonein\%}, and \verb{\%onein\%}
a single logical value (or empty logical if \code{x} has length \code{0}) is
returned. For \verb{\%notin\%}, a logical vector of the same length as
\code{x} is returned.
}
\description{
Infix operators for common tasks.

\verb{\%''\%} and \verb{\%""\%} return the right-hand side if the left-hand side is
an empty string (\code{""}).

\verb{\%!||\%} returns the right-hand side if the left-hand side is not
\code{NULL}.

\verb{\%0\%} returns the right-hand side if the left-hand side has length 0.

\verb{\%allin\%} returns \code{TRUE} if all elements of \code{x} are in \code{table}.

\verb{\%anyin\%} returns \code{TRUE} if any elements of \code{x} are in \code{table}.

\verb{\%nonein\%} returns \code{TRUE} if none of the elements of \code{x} are in \code{table}.

\verb{\%onein\%} returns \code{TRUE} if exactly one element of \code{x} is in \code{table}.

\verb{\%notin\%} returns \code{TRUE} for elements of \code{x} that are not in \code{table}.
This is implemented in the same way as base \strong{R} and will be
replaced by the base version in the \strong{R} versions that have it.
}
\details{
The \verb{\%*in\%} operators follow the semantics of \code{\%in\%} for \code{NULL}
values:
\itemize{
\item Singular \code{NULL}'s on the lhs always returns a length \code{0} logical vector.
\item \code{NULL} elements are not considered equal to singular \code{NULL}'s so will
give a \code{TRUE} for \verb{\%nonein\%} and \verb{\%notin\%} and \code{FALSE} for \verb{\%allin\%},
\verb{\%anyin\%} and \verb{\%onein\%}.
}

See \code{\%in\%} semantics:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{NULL \%in\% NULL
#> logical(0)
NULL \%in\% list(1, NULL)
#> logical(0)
list(1, NULL) \%in\% NULL
#> [1] FALSE FALSE
list(1, NULL) \%in\% list(1, NULL)
#> [1] TRUE TRUE
}\if{html}{\out{</div>}}
}
\examples{
"" \%''\% "default" # if lhs is "", return rhs

NULL \%!||\% "default" # if lhs is NULL, return *lhs* (NULL)
# useful for when using NULL as a default value
# or when using elements of a list that may be NULL
# e.g.,
lst <- list(a = 1, b = 2)
x <- lst$nope \%!||\% mean(lst$nope) # returns NULL

integer(0) \%0\% 5L # if lhs is length 0, return rhs

c(1, 2, 3) \%allin\% c(1, 2, 3, 4) # TRUE

c(1, 2, 3) \%anyin\% c(1, 2, 3, 4) # TRUE

c(1, 2, 3) \%nonein\% c(4, 5, 6) # TRUE

c(1, 2, 3) \%onein\% c(1, 4, 5) # TRUE

c(1, 2, 3) \%notin\% c(4, 5, 6) # TRUE
}
