r-lib / tidyselect

A backend for functions taking tidyverse selections
https://tidyselect.r-lib.org
Other
124 stars 39 forks source link

Can we add more context for `Can't rename in this context` errors? #336

Open DavisVaughan opened 1 year ago

DavisVaughan commented 1 year ago

This came up in https://github.com/tidyverse/dplyr/issues/6745

We've started using allow_rename = FALSE more often when our interfaces use tidy selection purely for selection (i.e. when we don't allow named inputs for possible renaming), so this error has popped up more often.

I think it would be useful if we could mention the expression causing the issue, like how we do here:

library(tidyselect)
library(rlang)

eval_select(expr(all_of(x)), mtcars)
#> Error:
#> ! Problem while evaluating `all_of(x)`.
#> Caused by error in `as_indices_impl()`:
#> ! object 'x' not found

I'm imagining something like this for https://github.com/tidyverse/dplyr/issues/6745:

#> Error in `rename_with()`:
#> ! Problem while evaluating `all_of(x)`.
#> ! Can't rename variables in this context.
DavisVaughan commented 1 month ago

Another one https://github.com/tidyverse/tidyr/issues/1481