match_arg | R Documentation |
This function works identically to match.arg()
, except that the
error messages include the actual name of the argument. So for
example, if the argument name is "size", instead of a generic error
message "'arg' must be of length 1", you will get
"'size' must be of length 1". This makes it easier for users to
figure out which argument has been passed incorrectly.
match_arg( arg, choices, several.ok = FALSE, arg_name = substitute(arg), ignore.case = FALSE )
arg |
a character vector (of length one unless |
choices |
a character vector of candidate values, often missing, see ‘Details’. |
several.ok |
logical specifying if |
arg_name |
The name of the argument. Normally you do not need to specify this yourself, as it is detected automatically. However, if your variable name is not the name of the argument, you will need to specify this. |
ignore.case |
If TRUE, case will be ignored when comparing the argument to the choices. Note that the matching choice will be returned in its original case, regardless of the case of arg. |
choices <- c("red", "green", "blue") color <- "blue" match_arg(color, choices) color <- "pink" try(match_arg(color, choices)) try(match_arg(color, choices, arg_name = "colour")) color <- "BLUE" match_arg(color, choices, ignore.case = TRUE) try(match_arg(color, choices))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.