| check_numeric | R Documentation |
Checks that x is numeric. Uses is.numeric(), which accepts both
"double" and "integer" inputs - the right semantics for "is this a
number?". Prefer this over check_inherits(x, "numeric"), which
rejects integers because their literal class is "integer", not
"numeric" (a long-standing R/S3 quirk). This trips up wire-format
callers: jsonlite::fromJSON("1") returns an integer, and the value
would then fail inherits(., "numeric") despite being a perfectly
good number.
check_numeric(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Vector to check. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_numeric(1L)
check_numeric(1.5)
check_numeric(c(1, 2, 3))
# Throws error:
try(check_numeric("1"))
try(check_numeric(TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.