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

is_unsorted

Is the input unsorted?


Description

Checks to see if the input is unsorted (without the cost of sorting it).

Usage

assert_is_unsorted(x, na.rm = FALSE, strictly = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_unsorted(x, na.rm = FALSE, strictly = FALSE,
  .xname = get_name_in_parent(x))

Arguments

x

Input to check.

na.rm

If TRUE, remove NAs before checking.

strictly

If TRUE, equal values count as unsorted.

severity

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

.xname

Not intended to be used directly.

Value

is_unsorted reimplements is.unsorted, providing more information on failure. assert_is_unsorted returns nothing but throws an error if is_unsorted returns FALSE.

Note

The builtin function is.unsorted usually returns NA when the input is recursive and has length 2, though for some classes (particularly data.frames) it returns a TRUE or FALSE value. The logic behind those is difficult to interpret, and gives odd results, so is_unsorted always returns NA in this case.

See Also

Examples

assert_is_unsorted(c(1, 3, 2))
assert_is_unsorted(c(1, 1, 2), strictly = TRUE)
# These checks should fail.
assertive.base::dont_stop({
  assert_is_unsorted(c(1, 1, 2))
  assert_is_unsorted(c(2, 1, 0))
})

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.