% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/type-check.R
\name{stop_input_type}
\alias{stop_input_type}
\title{Throw a type mismatch error}
\usage{
stop_input_type(
  x,
  what,
  ...,
  allow_na = FALSE,
  allow_null = FALSE,
  show_value = TRUE,
  arg = caller_arg(x),
  call = caller_env()
)
}
\arguments{
\item{x}{The object that does not conform to \code{what}. Its
"friendly type" is used in the error message.}

\item{what}{The friendly expected type as a string. Can be a
character vector of expected types, in which case the error
message mentions all of them in an "or" enumeration.}

\item{...}{Additional arguments passed to \code{\link[=abort]{abort()}}.}

\item{allow_na}{If \code{TRUE}, an \code{NA} description is appended to
\code{what} in the error message.}

\item{allow_null}{If \code{TRUE}, a \code{NULL} description is appended to
\code{what} in the error message.}

\item{show_value}{Whether to show the actual value in the error
message.}

\item{arg}{An argument name as a string. This argument
will be mentioned in error messages as the input that is at the
origin of a problem.}

\item{call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\value{
Throws an error, does not return.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}

\code{stop_input_type()} throws an error when an argument has the wrong
type, producing a friendly error message that includes the expected
type and the actual type of the input.
}
\examples{
check_character <- function(
  x,
  ...,
  allow_null = FALSE,
  arg = caller_arg(x),
  call = caller_env()
) {
  if (!missing(x)) {
    if (is_character(x)) {
      return(invisible(NULL))
    }
    if (allow_null && is_null(x)) {
      return(invisible(NULL))
    }
  }

  stop_input_type(
    x,
    "a character vector",
    ...,
    allow_null = allow_null,
    arg = arg,
    call = call
  )
}

# Succeeds
check_character(letters)

# Fails
try(check_character(42))
}
\seealso{
Other input checkers: 
\code{\link{check_data_frame}()},
\code{\link{check_type_number}},
\code{\link{check_type_scalar}}
}
\concept{input checkers}
