assertive.types (version 0.0-1)

assert_is_a_number: Is the input numeric?

Description

Checks to see if the input is numeric.

Usage

assert_is_a_number(x, severity = getOption("assertive.severity", "stop"))

assert_is_numeric(x, severity = getOption("assertive.severity", "stop"))

is_a_number(x, .xname = get_name_in_parent(x))

is_numeric(x, .xname = get_name_in_parent(x))

Arguments

x
Input to check.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
.xname
Not intended to be used directly.

Value

  • is_numeric wraps is.numeric, providing more information on failure. is_a_number returns TRUE if the input is numeric and scalar. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

See Also

is.numeric and is_scalar.

Examples

Run this code
assert_is_numeric(1:10)
assert_is_a_number(pi)
assert_is_a_number(1L)
assert_is_a_number(NA_real_)
#These examples should fail.
assertive.base::dont_stop(assert_is_numeric(c(TRUE, FALSE)))
assertive.base::dont_stop(assert_is_a_number(1:10))
assertive.base::dont_stop(assert_is_a_number(numeric()))

Run the code above in your browser using DataCamp Workspace