assertive.numbers (version 0.0-2)

assert_all_are_divisible_by: Is the input divisible by a number?

Description

Checks to see if the input is divisible by some number.

Usage

assert_all_are_divisible_by(x, n, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_divisible_by(x, n, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_even(x, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_even(x, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_odd(x, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_odd(x, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
is_divisible_by(x, n, tol = 100 * .Machine$double.eps, .xname = get_name_in_parent(x))
is_even(x, tol = 100 * .Machine$double.eps, .xname = get_name_in_parent(x))
is_odd(x, tol = 100 * .Machine$double.eps, .xname = get_name_in_parent(x))

Arguments

x
A numeric vector to divide.
n
A numeric vector to divide by.
tol
Differences from zero smaller than tol are not considered.
na_ignore
A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
.xname
Not intended to be used directly.

Value

TRUE if the input x is divisible by n, within the specified tolerance.

See Also

is_whole_number

Examples

Run this code
is_divisible_by(1:10, 3)
is_divisible_by(-5:5, -2)
is_divisible_by(1.5:10.5, c(1.5, 3.5))
assert_any_are_even(1:10)
assertive.base::dont_stop(assert_all_are_even(1:10))

Run the code above in your browser using DataCamp Workspace