validate_argument {insight} | R Documentation |
Validate arguments against a given set of options
Description
This is a replacement for match.arg()
, however, the error
string should be more informative for users. The name of the affected argument
is shown, and possible typos as well as remaining valid options. Note that
the argument several.ok
is always FALSE
in validate_argument()
, i.e.
this function - unlike match.arg()
- does not allow evaluating several
valid options at once.
Usage
validate_argument(argument, options)
Arguments
argument |
The bare name of the argument to be validated. |
options |
Valid options, usually a character vector. |
Value
argument
if it is a valid option, else an error is thrown.
Examples
foo <- function(test = "small") {
validate_argument(test, c("small", "medium", "large"))
}
foo("small")
# errors:
# foo("masll")
[Package insight version 1.3.0 Index]