| arg_numeric | R Documentation |
Checks whether an argument is numeric, with some additional constraints if desired. arg_numeric() simply checks whether the argument is numeric. arg_number() checks whether the argument is a numeric scalar (i.e., a single number). arg_whole_numeric() and arg_whole_number() check whether the argument is a whole numeric vector or scalar, respectively. arg_counts() and arg_count() check whether the argument is a non-negative whole numeric vector or scalar, respectively.
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)
x |
the argument to be checked |
.arg |
the name of the argument supplied to |
.msg |
an optional alternative message to display if an error is thrown instead of the default message. |
.call |
the execution environment of a currently running function, e.g. |
A whole number is decided by testing whether the value is an integer (i.e., using is.integer()) or if abs(x - trunc(x)) < sqrt(.Machine$double.eps). This is the same tolerance used by all.equal() to compare values.
Returns NULL invisibly if an error is not thrown.
is.integer(), rlang::is_integerish()
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.