An argument x
is a numerical range if and only if (all conditions must be met):
Is an object of type:
integer
ordouble
.Is a vector or length two such that the value of the first number is not less than the second number. Equalness is allowed if and only if
unique
flag is set toTRUE
.Lower bound of the interval is greater than or equal to
lower
and upper bound of the interval is less than or equal toupper
.It contains only finite (given that
finite
isTRUE
) and non-missing values.
Usage
check_range(x, lower = -Inf, upper = Inf, finite = FALSE, unique = TRUE)
assert_range(
x,
lower = -Inf,
upper = Inf,
finite = FALSE,
unique = TRUE,
.var.name = checkmate::vname(x),
add = NULL
)
test_range(x, lower = -Inf, upper = Inf, finite = FALSE, unique = TRUE)
expect_range(
x,
lower = -Inf,
upper = Inf,
finite = FALSE,
unique = TRUE,
info = NULL,
label = vname(x)
)
Arguments
- x
[any]
Object to check.- lower
[
numeric(1)
]
Lower value all elements ofx
must be greater than or equal to.- upper
[
numeric(1)
]
Upper value all elements ofx
must be lower than or equal to.- finite
[
logical(1)
]
Check for only finite values? Default isFALSE
.- unique
[
logical(1)
]
Must all values be unique? Default isFALSE
.- .var.name
[
character(1)
]
Name of the checked object to print in assertions. Defaults to the heuristic implemented invname
.- add
[
AssertCollection
]
Collection to store assertion messages. SeeAssertCollection
.- info
[
character(1)
]
Extra information to be included in the message for the testthat reporter. Seeexpect_that
.- label
[
character(1)
]
Name of the checked object to print in messages. Defaults to the heuristic implemented invname
.
See also
assertions
for more details.
Examples
check_range(c(1, 5))
#> [1] TRUE
check_range(c(-5, 1))
#> [1] TRUE
check_range(c(4, 1))
#> [1] "x must be a valid numerical range. Must be sorted"
check_range(c(1, 1))
#> [1] "x must be a valid numerical range. Contains duplicated values, position 2"
check_range(c(1, 1), unique = FALSE)
#> [1] TRUE
check_range(1:3)
#> [1] "x must be a valid numerical range. Must have length 2, but has length 3"