View source: R/validate_args.R
| validate_args | R Documentation |
Low-level helper used by the data validation of the healthiar functions
(e.g. validate_input_attribute(), socialize(), monetize()).
It takes the list of argument values, the names of the arguments to be
checked and a predicate returning TRUE for the valid values.
Arguments that are NULL (i.e. not entered by the user) are skipped,
so the callers do not have to filter them beforehand.
validate_args(
args,
arg_names,
is_valid,
message,
report = "first",
type = "error"
)
args |
|
arg_names |
|
is_valid |
|
message |
|
report |
|
type |
|
report
Use "first" when the message is specific to one argument
(e.g. the options of a categorical argument), so that the users are not
confronted with the options of all arguments at once.
Use "all" when the message is the same for all arguments
(e.g. "must not be lower than 0"), so that the users can correct all of them
in one go instead of one at a time.
Order of the calls
The order of the calls matters: a predicate is only safe once the previous
calls have ruled out the value types it cannot handle. E.g. checking whether
a value is a whole number (x == floor(x)) requires that the
numeric check has already been passed.
This function returns nothing. It is called for its side effect, i.e. an error or a warning if any of the argument values is not valid.
Alberto Castro & Axel Luyten
## Not run:
# Message about one single argument
validate_args(
args = input_args$value,
arg_names = c("n_quantile", "population"),
is_valid = is.numeric,
message = "{arg} must contain numeric value(s).")
# Message listing all the arguments concerned
validate_args(
args = input_args$value,
arg_names = c("prop_pop_exp", "dw_central"),
is_valid = function(x){x <= 1},
message = "The values in the following arguments must not be higher than 1: {arg}.",
report = "all")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.