This function provides a standardized response to input checks, ensuring consistency.
Usage
input_check_response(
check,
var_name = NULL,
error = TRUE,
prefix = "Input {.var {var_name}} is bad:"
)
Arguments
- check
[
TRUE
|character(1)
|list()
]
Matches the return value of thecheck*
functions from the{checkmate}
package, i.e., eitherTRUE
if the check was successful, or acharacter
(the error message) else.Can also be a
list
of multiple such values for alternative criteria, where at least one must beTRUE
for a successful check.- var_name
[
NULL
|character(1)
]
Optionally specifies the name of the input being checked. This name will be used for the default value of theprefix
argument.- error
[
logical(1)
]
Ifcheck
is notTRUE
(or no element incheck
isTRUE
, ifcheck
is alist
), throw an error?- prefix
[
character(1)
]
A prefix for the thrown error message, only relevant iferror
isTRUE
.
Value
TRUE
if check
is TRUE
(or any element in check
is TRUE
, if check
is a list
) . Else, depending on error
:
If
error
isTRUE
, throws an error.If
error
isFALSE
, returnsFALSE
.
See also
Other package helpers:
Dictionary
,
Storage
,
identical_structure()
,
match_arg()
,
package_logo()
,
print_data.frame()
,
print_matrix()
,
system_information()
,
unexpected_error()
,
user_confirm()
Examples
x <- "1"
y <- 1
### check is successful
input_check_response(
check = checkmate::check_character(x),
var_name = "x",
error = TRUE
)
#> [1] TRUE
### alternative checks
input_check_response(
check = list(
checkmate::check_character(x),
checkmate::check_character(y)
),
var_name = "x",
error = TRUE
)
#> [1] TRUE
### standardized check response
if (FALSE) { # \dontrun{
input_check_response(
check = checkmate::check_character(y),
var_name = "y",
error = TRUE
)
input_check_response(
check = list(
checkmate::check_flag(x),
checkmate::check_character(y)
),
var_name = "y",
error = TRUE
)
} # }