Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_monotonic_increasing

Is the vector monotonically increasing or decreasing?


Description

Checks to see if the input is monotonically increasing or decreasing.

Usage

assert_is_monotonic_increasing(x, strictly = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_is_monotonic_decreasing(x, strictly = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_monotonic_increasing(x, strictly = FALSE, .xname = get_name_in_parent(x))

is_monotonic_decreasing(x, strictly = FALSE, .xname = get_name_in_parent(x))

Arguments

x

Input to check.

strictly

Logical. If TRUE, the input is checked for being strictly monotonic; that is, consecutive values cannot be equal.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

Examples

x <- c(1, 2, 2, 1, 3, 2)
is_monotonic_increasing(x)
is_monotonic_increasing(x, TRUE)
is_monotonic_decreasing(x)
is_monotonic_decreasing(x, TRUE)

# Also works with, e.g., dates & times
is_monotonic_increasing(Sys.time() + x)

# These checks should fail
assertive.base::dont_stop({
  assert_is_monotonic_increasing(x)
  assert_is_monotonic_decreasing(x)
})

assertive.properties

Assertions to Check Properties of Variables

v0.0-4
GPL (>= 3)
Authors
Richard Cotton [aut, cre]
Initial release
2016-12-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.