r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
508 stars 138 forks source link

`arg_match0()` error should interpolate `values` #1545

Closed DavisVaughan closed 1 year ago

DavisVaughan commented 1 year ago

i.e. list "foo" and "bar" rather than saying values in the error here

library(rlang)

fn <- function(x) {
  arg_match0(x, values = c("foo", "bar"))
}

fn(c("a", "b"))
#> Error in `arg_match()`:
#> ! `arg` must be length 1 or a permutation of `values`.

#> Backtrace:
#>     ▆
#>  1. ├─global fn(c("a", "b"))
#>  2. │ └─rlang::arg_match0(x, values = c("foo", "bar"))
#>  3. └─rlang:::stop_arg_match(w, x, y, z)
#>  4.   └─rlang::abort(msg, call = quote(arg_match()), arg = "arg")

Created on 2023-01-23 with reprex v2.0.2.9000

DavisVaughan commented 1 year ago

Oh and it looks like this needs to use the error_call?