Is the input divisible by a number?

Share:

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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.

Note

is_even and is_odd are shortcuts for divisibility by two.

See Also

is_whole_number

Examples

1
2
3
4
5
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))