Check strictly changing vector
check_strict.RdCheck if arg is a strictly increasing/decreasing numeric vector.
Usage
check_strict_decreasing(
arg,
na.rm = FALSE,
signal = "error",
msg = NULL,
call. = FALSE
)
check_strict_increasing(
arg,
na.rm = FALSE,
signal = "error",
msg = NULL,
call. = FALSE
)Arguments
- arg
(object)
The argument to check.- na.rm
(scalar logical:
c(FALSE, TRUE))
Whether or not to remove missing values before checking.- signal
(string:
c("error", "warning", "message"))
Must be one of"error","warning", or"message"."error"(default) callsbase::stop()to signal an error message."warning"callsbase::warning()to signal a warning message."message"callsbase::message()to signal a message.- msg
(string or
NULL:NULL)
A string that replaces the default message. Set asNULLto use the default message.- call.
(Scalar logical:
c(FALSE, TRUE))
Passed tostop()orwarning(). The defaultmsgincludes it's own formatted call, hencecall.should beFALSE(default). If you insert your ownmsg, then you may wantcall. = TRUE.
Examples
#----------------------------------------------------------------------------
# check_strict_*() examples
#----------------------------------------------------------------------------
library(bkcheck)
#----------------------------------------------------------------------------
# check_strict_decreasing()
#----------------------------------------------------------------------------
f <- function(x) {
x |>
check_numeric() |>
check_strict_decreasing()
}
f(10:1)
try(f(c(3, 3, 2, 1)))
#> Error : Argument `x` must be strictly decreasing.
#>
#> First violation at index 2: x[1] = 3, x[2] = 3
#> class(x) = 'numeric'
#> length(x) = 4
#>
#> Call: f(x = c(3, 3, 2, 1))
try(f(1:2))
#> Error : Argument `x` must be strictly decreasing.
#>
#> First violation at index 2: x[1] = 1, x[2] = 2
#> class(x) = 'integer'
#> length(x) = 2
#>
#> Call: f(x = 1:2)
#----------------------------------------------------------------------------
# check_strict_increasing()
#----------------------------------------------------------------------------
f <- function(x) {
x |>
check_numeric() |>
check_strict_increasing()
}
f(1:10)
try(f(c(1, 2, 3, 3)))
#> Error : Argument `x` must be strictly increasing.
#>
#> First violation at index 4: x[3] = 3, x[4] = 3
#> class(x) = 'numeric'
#> length(x) = 4
#>
#> Call: f(x = c(1, 2, 3, 3))
try(f(2:1))
#> Error : Argument `x` must be strictly increasing.
#>
#> First violation at index 2: x[1] = 2, x[2] = 1
#> class(x) = 'integer'
#> length(x) = 2
#>
#> Call: f(x = 2:1)