Skip to contents

Validates that the elements are in order and reports the position of the first element that breaks it.

Usage

require_sorted(restriction, decreasing = FALSE, strict = FALSE)

Arguments

restriction

a restriction object.

decreasing

logical; if TRUE, requires decreasing order.

strict

logical; if TRUE, equal neighbours are a violation.

Value

The modified restriction object.

Details

Works on numeric, character, logical, Date, POSIXct, difftime and ordered-factor values; other input fails with a type error. Character values compare in the collation order of the session locale. NA elements are skipped; chain require_no_na() to reject them.

Examples

ts_v <- restrict("time") |> require_sorted(strict = TRUE)
ts_v(c(1, 2, 5))
try(ts_v(c(1, 3, 2)))
#> Error : time: must be strictly increasing order
#>   Found: 2 after 3
#>   At: 3