Usage
check_numeric(
x,
lower = -Inf,
upper = Inf,
finite = FALSE,
any_missing = TRUE,
all_missing = TRUE,
len = NULL,
min_len = NULL,
max_len = NULL,
null_ok = FALSE,
.names = deparse(substitute(x))
)
assert_numeric(
x,
lower = -Inf,
upper = Inf,
finite = FALSE,
any_missing = TRUE,
all_missing = TRUE,
len = NULL,
min_len = NULL,
max_len = NULL,
null_ok = FALSE,
.names = deparse(substitute(x))
)
test_numeric(
x,
lower = -Inf,
upper = Inf,
finite = FALSE,
any_missing = TRUE,
all_missing = TRUE,
len = NULL,
min_len = NULL,
max_len = NULL,
null_ok = FALSE,
.names = deparse(substitute(x))
)Arguments
- x
Any R object.
- lower
(Optional) A value of the same class as
xindicating the minimum value ofx(Default:-Inf).- upper
(Optional) A value of the same class as
xindicating the maximum value ofx(Default:Inf).- finite
(Optional) A
logicalflag indicating if all values must be finite (Default:TRUE).- any_missing
(Optional) A
logicalflag indicating if missing values are allowed (Default:TRUE).- all_missing
(Optional) A
logicalflag indicating if all missing values are allowed (Default:TRUE).- len
(Optional) An integer number indicating the expected length of
x(Default:NULL).- min_len
(Optional) An integer number indicating the minimum length of
x(Default:NULL).- max_len
(Optional) An integer number indicating the maximum length of
x(Default:NULL).- null_ok
(Optional) A
logicalflag indicating ifNULLvalues are allowed (Default:FALSE).- .names
(Optional) A
charactervector specifying the names of the objects being tested. This argument is used internally and should not be set by the user.
Value
test_*:TRUEif it passes the test;FALSEotherwise.check_*:TRUEif it passes the test; a string with a message otherwise.assertion_*: The same input (as invisible) if it passes the test; an error message otherwise.
Examples
test_numeric("a")
#> [1] FALSE
#> [1] FALSE # Expected
test_numeric(lubridate::duration())
#> [1] FALSE
#> [1] FALSE # Expected
test_numeric(1:10)
#> [1] TRUE
#> [1] TRUE # Expected
x <- 1:2
check_numeric(x, len = 1) |> cli::cli_alert_warning()
#> ! x must have 1 element.
#> ! x must have 1 element. # Expected
check_numeric(x, min_len = 3) |> cli::cli_alert_warning()
#> ! x must have 3 or more elements.
#> ! x must have 3 or more elements. # Expected
check_numeric(x, max_len = 1) |> cli::cli_alert_warning()
#> ! x must have 1 or less elements.
#> ! x must have 1 or less elements. # Expected
x <- 1
check_numeric(1, min_len = 2, max_len = 3) |> cli::cli_alert_warning()
#> ! 1 must have 2 or more elements.
#> ! x must have a length between 2 and 3. # Expected