Description Usage Arguments Value Note See Also Examples
Checks to see if the input is numeric.
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))
|
x |
Input to check. |
severity |
How severe should the consequences of the assertion be?
Either |
.xname |
Not intended to be used directly. |
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
.
numeric
means either double or integer, inc this case.
is_integer
, is.numeric
and
is_scalar
.
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))
|
$`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'.>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.