Check equal to
check_equals.RdCheck if arg is equal to x.
arg and x must be atomic vectors of the same length.
Arguments
- arg
(object)
The argument to check.- x
(Atomic vector)
The vector whichargmust be equal to. Must be the same length asarg.- 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_equals() examples
#----------------------------------------------------------------------------
library(bkcheck)
f <- function(x) {
vec <- 1:2
x |>
check_equals(vec)
}
x1 <- 1:2
x2 <- 2:3
f(x1)
try(f(x2))
#> Error : Argument `x` must be equal to the target values.
#>
#> Target: 1, 2
#> In `x` only: 3
#> In target only: 1
#> length(x) = 2
#> length(target) = 2
#>
#> Call: f(x = x2)