Learn R Programming

assertive.numbers (version 0.0-2)

assert_all_are_equal_to: How does the input relate to a value?

Description

Is x equal/not equal/greater than/less than y?

Usage

assert_all_are_equal_to(x, y, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_equal_to(x, y, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_not_equal_to(x, y, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_not_equal_to(x, y, tol = 100 * .Machine$double.eps, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_greater_than(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_greater_than(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_greater_than_or_equal_to(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_greater_than_or_equal_to(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_less_than(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_less_than(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_less_than_or_equal_to(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_less_than_or_equal_to(x, y, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
is_equal_to(x, y, tol = 100 * .Machine$double.eps, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))
is_not_equal_to(x, y, tol = 100 * .Machine$double.eps, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))
is_greater_than(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))
is_greater_than_or_equal_to(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))
is_less_than(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))
is_less_than_or_equal_to(x, y, .xname = get_name_in_parent(x), .yname = get_name_in_parent(x))

Arguments

x
A numeric vector.
y
Another numeric vector, typically scalar or the same length as x. See note.
tol
Values within tol are considered equal.
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.
.yname
Not intended to be used directly.

Value

TRUE if the input x is equal/not equal/greater than/less than y

Examples

Run this code
# Approximate and exact floating point comparisons:
# See FAQ on R 7.31
x <- sqrt(2) * sqrt(2)
is_equal_to(x, 2)
is_equal_to(x, 2, tol = 0)
is_not_equal_to(x, 2)
is_not_equal_to(x, 2, tol = 0)

# Elements of x and y are recycled
is_equal_to(1:6, 1:3)

# Inequalities
x <- c(1 - .Machine$double.neg.eps, 1, 1 + .Machine$double.eps)
is_greater_than(x, 1)
is_greater_than_or_equal_to(x, 1)
is_less_than(x, 1)
is_less_than_or_equal_to(x, 1)

Run the code above in your browser using DataLab