Checks that lower and upper form a sensible (non-inverted) range. By
default equal bounds are allowed (lower <= upper, a point range); set
allow_equal = FALSE to require them strictly ordered (lower < upper),
rejecting lower == upper — handy for half-open windows like start < end.
Works for any comparable type: numbers, dates, date-times, strings. If either
bound is NULL the range is treated as open-ended on that side and the check
passes — handy for optional start / end arguments.
Usage
assert_range(
lower,
upper,
allow_equal = TRUE,
arg_lower = rlang::caller_arg(lower),
arg_upper = rlang::caller_arg(upper),
call = rlang::caller_env()
)Arguments
- lower
The lower bound, or
NULLfor unbounded below.- upper
The upper bound, or
NULLfor unbounded above.- allow_equal
Single logical. If
TRUE(default) the bounds may be equal (lower <= upper); ifFALSEthey must be strictly ordered (lower < upper), so equal bounds fail.- arg_lower
Name used to refer to
lowerin error messages.- arg_upper
Name used to refer to
upperin error messages.- call
Environment used as the error's call context. Defaults to the calling function, so errors point at the user's code.
