Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arg_match() error message only mentions the first element of arg #1682

Open
ndunnewind opened this issue Jan 22, 2024 · 2 comments · May be fixed by #1733
Open

arg_match() error message only mentions the first element of arg #1682

ndunnewind opened this issue Jan 22, 2024 · 2 comments · May be fixed by #1733

Comments

@ndunnewind
Copy link

If arg in arg_match() is a character vector with more than one element (and is not a permuted version of values) the error message only mentions the first element. This is confusing if the first element is actually in values, as shown below.

fn <- function(x = c("foo", "bar")) rlang::arg_match(x)

fn(c("foo", "baz"))
#> Error in `fn()`:
#> ! `x` must be one of "foo" or "bar", not "foo".

Created on 2024-01-22 with reprex v2.1.0

@romainfrancois
Copy link
Contributor

It's also an issue when x is a vector and multiple is set to TRUE:

sorting_hat <- function(house = c("Gryffindor", "Slytherin", "Ravenclaw", "Hufflepuff"), multiple = FALSE) {
  rlang::arg_match(house, multiple = multiple)
}
sorting_hat(c("Gryffindor", "Slytherin"), multiple = TRUE)
#> [1] "Gryffindor" "Slytherin"
sorting_hat(c("Gryffindor", "Slytherin"), multiple = FALSE)
#> Error in `sorting_hat()`:
#> ! `house` must be one of "Gryffindor", "Slytherin", "Ravenclaw", or
#>   "Hufflepuff", not "Gryffindor".

Created on 2024-04-05 with reprex v2.1.0

@olivroy

This comment was marked as off-topic.

@olivroy olivroy linked a pull request Jul 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants