Is the input in range?

Description

Checks to see if the input is within an numeric interval.

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
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
assert_all_are_in_closed_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_any_are_in_closed_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_all_are_in_left_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_any_are_in_left_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_all_are_in_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_any_are_in_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_all_are_in_range(x, lower = -Inf, upper = Inf,
  lower_is_strict = FALSE, upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_in_range(x, lower = -Inf, upper = Inf,
  lower_is_strict = FALSE, upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_in_right_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_any_are_in_right_open_range(x, lower = -Inf, upper = Inf,
  na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

assert_all_are_negative(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_negative(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_non_negative(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_non_negative(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_non_positive(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_non_positive(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_percentages(x, lower_is_strict = FALSE,
  upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_percentages(x, lower_is_strict = FALSE,
  upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_positive(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_positive(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_all_are_proportions(x, lower_is_strict = FALSE,
  upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_proportions(x, lower_is_strict = FALSE,
  upper_is_strict = FALSE, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_in_closed_range(x, lower = -Inf, upper = Inf,
  .xname = get_name_in_parent(x))

is_in_left_open_range(x, lower = -Inf, upper = Inf,
  .xname = get_name_in_parent(x))

is_in_open_range(x, lower = -Inf, upper = Inf,
  .xname = get_name_in_parent(x))

is_in_range(x, lower = -Inf, upper = Inf, lower_is_strict = FALSE,
  upper_is_strict = FALSE, .xname = get_name_in_parent(x))

is_in_right_open_range(x, lower = -Inf, upper = Inf,
  .xname = get_name_in_parent(x))

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

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

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

is_percentage(x, lower_is_strict = FALSE, upper_is_strict = FALSE,
  .xname = get_name_in_parent(x))

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

is_proportion(x, lower_is_strict = FALSE, upper_is_strict = FALSE,
  .xname = get_name_in_parent(x))

Arguments

x

Input to check.

lower

Lower bound for the interval.

upper

Upper bound for the interval.

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".

lower_is_strict

If TRUE, the lower bound is open (strict) otherwise it is closed.

upper_is_strict

If TRUE, the upper bound is open (strict) otherwise it is closed.

.xname

Not intended to be used directly.

Value

The is_* functions return TRUE if the input is within an interval. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

Note

is_in_range provides the most flexibility in determining if values are within a numeric interval. The other functions restrict the input arguments for convience in common cases. For example, is_percentage forces the interval to be from 0 to 100. The function is not vectorized by the lower_is_strict and upper_is_strict for speed (these are assumed to be scalar logical values).

Examples

1
2
3
4
5
6