ERRORs are thrown when a match is not made and where the match is
ambiguous. However, sometimes ambiguities are inevitable. Consider the case
where choices = c("ab", "abc"), then there's no way to choose "ab"
because "ab" is a prefix for "ab" and "abc". If this is the case, you
need to provide a full match, i.e. using arg = "ab" will get you "ab"
without an error, however arg = "a" will throw an ambiguity error.
When choices is NULL, the choices are obtained from a default setting
for the formal argument arg of the function from which str_match_arg was
called. This is consistent with base::match.arg(). See the examples for
details.
When arg and choices are identical and several_ok = FALSE, the first
element of choices is returned. This is consistent with
base::match.arg().
This function inspired by RSAGA::match.arg.ext(). Its behaviour is almost
identical (the difference is that RSAGA::match.arg.ext(..., ignore.case = TRUE) always returns in all lower case; strex::match_arg(..., ignore_case = TRUE) ignores case while matching but returns the element of choices in
its original case). RSAGA is a heavy package to depend upon so
strex::match_arg() is handy for package developers.
This function is designed to be used inside of other functions. It's fine to
use it for other purposes, but the error messages might be a bit weird.