% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg_is.R
\name{arg_is}
\alias{arg_is}
\alias{arg_is_not}
\title{Check Argument Class}
\usage{
arg_is(x, class, .arg = rlang::caller_arg(x), .msg = NULL, .call)

arg_is_not(x, class, .arg = rlang::caller_arg(x), .msg = NULL, .call)
}
\arguments{
\item{x}{the argument to be checked}

\item{class}{a character vector of one or more classes to check \code{x} against.}

\item{.arg}{the name of the argument supplied to \code{x} to appear in error messages. The default is to extract the argument's name using \code{\link[rlang:caller_arg]{rlang::caller_arg()}}. Ignored if \code{.msg} is supplied.}

\item{.msg}{an optional alternative message to display if an error is thrown instead of the default message.}

\item{.call}{the execution environment of a currently running function, e.g. \code{.call = rlang::current_env()}. The corresponding function call is retrieved and mentioned in error messages as the source of the error. Passed to \code{\link[=err]{err()}}. Set to \code{NULL} to omit call information. The default is to search along the call stack for the first user-facing function in another package, if any.}
}
\value{
Returns \code{NULL} invisibly if an error is not thrown.
}
\description{
Checks whether an argument is a of a specified class (\code{arg_is()}) or is not of a specified class (\code{arg_is_not()}).
}
\details{
\code{arg_is()} and \code{arg_is_not()} use \code{\link[=inherits]{inherits()}} to test for class membership. \code{arg_is()} throws an error only if no elements of \code{class(x)} are in \code{class}. \code{arg_is_not()} throws an error if any elements of \code{class(x)} are in \code{class}.

Sometimes this can be too permissive; combining \code{arg_is()} with \code{\link[=arg_and]{arg_and()}} can be useful for requiring that an object is of multiple classes. Alternatively, combining \code{arg_is_not()} with \code{\link[=arg_or]{arg_or()}} can be useful for requiring that an object is not a specific combination of classes. See Examples.
}
\examples{
obj <- structure(list(1),
                 class = "test")

try(arg_is(obj, "test"))            # No error
try(arg_is(obj, c("test", "quiz"))) # No error
try(arg_is(obj, "quiz"))            # Error

try(arg_is_not(obj, "test"))            # Error
try(arg_is_not(obj, c("test", "quiz"))) # Error
try(arg_is_not(obj, "quiz"))            # No error

# Multiple classes
obj2 <- structure(list(1),
                  class = c("test", "essay"))

try(arg_is(obj2, c("test", "quiz")))     # No error
try(arg_is_not(obj2, c("test", "quiz"))) # Error

## Require argument to be of multiple classes
try(arg_and(obj2,
            arg_is("test"),
            arg_is("quiz")))

## Require argument to not be a specific combination of
## multiple classes
try(arg_or(obj2,
           arg_is_not("test"),
           arg_is_not("essay")))
}
\seealso{
\code{\link[=inherits]{inherits()}}, \code{\link[=arg_or]{arg_or()}}; \code{\link[=arg_data]{arg_data()}} for testing for specific kinds of objects (vectors, matrices, data frames, and lists)
}
