% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg_numeric.R
\name{arg_numeric}
\alias{arg_numeric}
\alias{arg_number}
\alias{arg_whole_numeric}
\alias{arg_whole_number}
\alias{arg_counts}
\alias{arg_count}
\title{Check Numeric Argument}
\usage{
arg_numeric(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)

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

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

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

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

arg_count(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 is numeric, with some additional constraints if desired. \code{arg_numeric()} simply checks whether the argument is numeric. \code{arg_number()} checks whether the argument is a numeric scalar (i.e., a single number). \code{arg_whole_numeric()} and \code{arg_whole_number()} check whether the argument is a whole numeric vector or scalar, respectively. \code{arg_counts()} and \code{arg_count()} check whether the argument is a non-negative whole numeric vector or scalar, respectively.
}
\details{
A whole number is decided by testing whether the value is an integer (i.e., using \code{\link[=is.integer]{is.integer()}}) or if \code{abs(x - trunc(x)) < sqrt(.Machine$double.eps)}. This is the same tolerance used by \code{\link[=all.equal]{all.equal()}} to compare values.
}
\examples{
count <- 3
whole <- -4
num <- .943

try(arg_number(count))       # No error
try(arg_whole_number(count)) # No error
try(arg_count(count))        # No error

try(arg_number(whole))       # No error
try(arg_whole_number(whole)) # No error
try(arg_count(whole))        # Error: negatives not allowed

try(arg_number(num))       # No error
try(arg_whole_number(num)) # Error: not a whole number
try(arg_count(num))        # Error: not a count

nums <- c(0, .5, 1)

try(arg_number(nums))  # Error: not a single number
try(arg_numeric(nums)) # No error
try(arg_counts(nums))  # Error: not counts
}
\seealso{
\code{\link[=is.integer]{is.integer()}}, \code{\link[rlang:is_integerish]{rlang::is_integerish()}}
}
