-
Notifications
You must be signed in to change notification settings - Fork 39
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
Improve error message + tweak function signature respect error_arg
for allow_rename = FALSE
#358
Conversation
error_arg
for allow_rename = FALSE
… easier to remove if they are judged as not useful for some tests, with a cleaner diff (i.e. no comma to remove)
Would it be possible to make this into multiple much smaller PRs that do exactly 1 thing? It is much easier for us to confidently review a PR when it does 1 thing. In particular this is 3-4 PRs:
These each deserve their own PR where we can have detailed but focused conversation about each idea! I do love the enthusiasm though, and we really appreciate these contributions, they look great! |
if (is.null(error_arg)) { | ||
cli::cli_abort( | ||
"Can't rename variables in this context.", | ||
class = "tidyselect:::error_disallowed_rename", | ||
call = call | ||
) | ||
} else { | ||
cli::cli_abort(c( | ||
"Can't rename variables in this context.", | ||
i = "{.arg {error_arg}} can't be renamed." | ||
), | ||
class = "tidyselect:::error_disallowed_rename", | ||
call = call | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In #336 I think I was hoping that we could somehow mention the expression where the rename happens in the error message.
ensure_named()
is only called by vars_select_eval()
and that does have the expr
. So you could pass expr
through to ensure_named()
and use as_label(expr)
on it to get something nice to include in the error message. Like
expr <- as_label(expr)
cli::cli_abort(c(
"Can't rename variables during selection.",
i = "Rename detected in {.arg {error_arg}}, with expression {.code {expr}}."
),
class = "tidyselect:::error_disallowed_rename",
call = call
)
For something like c(all_of(x), y)
if the rename happens in the all_of(x)
, it would still report the full c(all_of(x), y)
as the place where the rename happened, but I think that is ok, it is hard to be more precise. I still think this would be a big improvement.
I think adding the argument name is nice, but maybe not quite as good as it could be on its own. For example this dplyr error from tidyverse/dplyr#6745 would have been:
#> Error in `rename_with()`:
#> ! Can't rename variables in this context.
#> i `.cols` can't be renamed.
But the user typed in mtcars %>% rename_with(toupper, all_of(v))
so .cols
isn't immediately meaningful to them. But this:
#> Error in `rename_with()`:
#> ! Can't rename variables in this context.
#> i Rename detected in `.cols`, with expression `all_of(v)`.
is probably enough for them to figure out where to look next, because it refers to something in their code
WDYT @lionel- ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use the "In argument" pattern for consistency.
#> Error in `rename_with()`:
#> ! Can't rename variables in this tidyselect context.
#> i In argument: `.cols = all_of(v)`.
Closing this since it was split into new PRs. |
I split the PR up
allow_empty = FALSE
+ add more context to error message by addingerror_arg
toeval_select()
#350 ) and supporterror_arg
forallow_rename = FALSE
Supporterror_arg
forallow_rename = FALSE
as well #359cnd_class = TRUE
when appropriate. Avoid nestedexpect_error()
in snapshot tests #361No rush, but I wondered if you had a date in mind for a cran release?