This function matches function arguments and is a modified version of
match.arg.
Arguments
- arg
[
character()]
The function argument.- choices
[
character()]
Allowed values forarg.- several.ok
[
logical(1)]
Isargallowed to have more than one element?- none.ok
[
logical(1)]
Isargallowed to have zero elements?
Value
The un-abbreviated version of the exact or unique partial match if there is
one. Otherwise, an error is signaled. An error is also signaled if
arg has more or fewer elements than allowed.
When several.ok is TRUE and (at least) one element of
arg has a match, all un-abbreviated versions of matches are returned
(elements without a match are dropped).
When none.ok is TRUE and arg has zero elements,
character(0) is returned.
Examples
match_arg("med", c("mean", "median"))
#> [1] "median"
match_arg(c("mea", "med"), c("mean", "median"), several.ok = TRUE)
#> [1] "mean" "median"
match_arg(character(), c("mean", "median"), none.ok = TRUE)
#> character(0)
try(match_arg("mode", c("mean", "median")))
#> Error : `"mode"` must be one of "mean" and "median".
