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

arg_is_NA(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)

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

\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 does not contain any \code{NA} values (\code{arg_no_NA()}), contains only \code{NA} values (\code{arg_all_NA()}), or is a scalar \code{NA} (\code{arg_is_NA()}).
}
\details{
\code{arg_no_NA()} throws an error when \code{anyNA(x)} is \code{0}. \code{arg_all_NA()} throws an error when \code{all(is.na(x))} is not \code{FALSE}. \code{arg_is_NA()} throws an error when \code{length(x)} is not 1 or \code{anyNA(x)} is \code{FALSE}.

\code{arg_no_NA()} is useful for checking that a meaningful argument was supplied. \code{arg_all_NA()} and \code{arg_is_NA()} are primarily used for in \code{\link[=arg_or]{arg_or()}} to denote that \code{NA} is an allowed argument.
}
\examples{
f <- function(x) {
  arg_no_NA(x)  ## x must not be NA
}

try(f(1))           ## No error
try(f(NA))          ## Error: x is NA
try(f(c(1, NA, 3))) ## Error: x contains NA

f2 <- function(y) {
  arg_all_NA(y) ## y must be NA
}

try(f2(NA))          ## No error
try(f2(c(NA, NA)))   ## No error
try(f2(1))           ## Error: y is not NA
try(f2(c(1, NA, 3))) ## Error: y is not all NA
}
\seealso{
\code{\link[=arg_non_null]{arg_non_null()}}, \code{\link[=arg_supplied]{arg_supplied()}}, \code{\link[=anyNA]{anyNA()}}
}
