Bug 16659 - match.arg with several.ok silently ignores incorrect arguments as long as there is one valid argument.
Summary: match.arg with several.ok silently ignores incorrect arguments as long as the...
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.2.3
Hardware: All All
: P5 trivial
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-01-07 15:48 UTC by Jim Hester
Modified: 2016-01-07 15:48 UTC (History)
0 users

See Also:


Attachments
Example implementation to fix this issue. (1.35 KB, patch)
2016-01-07 15:48 UTC, Jim Hester
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Hester 2016-01-07 15:48:47 UTC
Created attachment 1993 [details]
Example implementation to fix this issue.

When `several.ok = FALSE` (the default) `match.arg()` an error is signaled if `arg` is not in `choices`.

    match.arg("a", c("b", "c"), several.ok = FALSE)
    #> Error in match.arg("a", c("b", "c"), several.ok = FALSE): 'arg' should be one of "b", "c"

If `several.ok = TRUE` and none of the arguments are correct an error is signaled.

    match.arg("a", c("b", "c"), several.ok = TRUE)
    #> Error in match.arg("a", c("b", "c"), several.ok = TRUE): 'arg' should be one of "b", "c"

However if at least one of the given arguments are found no error is signaled.
   
   match.arg(c("a", "b"), c("b", "c"), several.ok = TRUE)
   #> [1] "b"

In this last case I think it would be more consistent to signal an error on the incorrect argument like the previous cases. The attached patch implements this behavior (changing the call to `all` to `any`, and updates the function documentation.