is_numeric: Is the input numeric?

Description Usage Arguments Value Note See Also Examples

View source: R/is-type-base.R

Description

Checks to see if the input is numeric.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
assert_is_a_double(x, severity = getOption("assertive.severity", "stop"))

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

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

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

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

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

is_double(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.

Note

numeric means either double or integer, inc this case.

See Also

is_integer, is.numeric and is_scalar.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# "numeric" fns work on double or integers; 
assert_is_numeric(1:10)

# Here we check for length 1 as well as type
assert_is_a_number(pi)
assert_is_a_number(1L)
assert_is_a_number(NA_real_)

# "double" fns fail for integers.
assert_is_a_double(pi)

#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()))
assertive.base::dont_stop(assert_is_double(1:10))

Example output

$`assert_is_numeric(c(TRUE, FALSE))`
<assertionError: is_numeric : c(TRUE, FALSE) is not of class 'numeric'; it has class 'logical'.>

$`assert_is_a_number(1:10)`
<assertionError: is_a_number : 1:10 has length 10, not 1.>

$`assert_is_a_number(numeric())`
<assertionError: is_a_number : numeric() has length 0, not 1.>

$`assert_is_double(1:10)`
<assertionError: is_double : 1:10 is not of class 'double'; it has class 'integer'.>

assertive.types documentation built on May 1, 2019, 10:31 p.m.