Argument Matching

2021-04-18

Ignoring case

base

The base function match.arg() is good, but it doesn’t offer the possiblity to ignore case during argument matching. Sometimes it’s good to ignore case; for example, if you’re matching the arguments c("yes", "no"), there’s no need to worry about case.

strex

The default behaviour of strex::match_arg() is to observe case, but case ignorance can be turned on with ignore_case = TRUE.

Error Messages

You can begin to see above that the error message from strex::match_arg() are more informative and nicely formatted. Here are a few more examples.

No matches

Multiple matches

Wrong arg length

Duplicate elements in choices

Not specifying choices

It’s OK not to specify choices in one circumstance: when arg is passed as a default argument of another function.

This is very strict though, only the symbol for the default argument can be passed, not any variant of it, not even something which evaluates to the same thing.