-
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
Throw classed error if allow_empty = FALSE
+ add more context to error message by adding error_arg
to eval_select()
#350
Conversation
allow_empty = FALSE
fails + add more context by adding error_arg
to eval_select()
allow_empty = FALSE
fails + add more context by adding error_arg
to eval_select()
allow_empty = FALSE
+ add more context to error message by adding error_arg
to eval_select()
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.
Thanks for taking a look! Just have some comments, please let me know if you need me to finish this up.
R/eval-select.R
Outdated
@@ -43,6 +43,8 @@ | |||
#' use predicates (i.e. in `where()`). If `FALSE`, will error if `expr` uses a | |||
#' predicate. Will automatically be set to `FALSE` if `data` does not | |||
#' support predicates (as determined by [tidyselect_data_has_predicates()]). | |||
#' @param error_arg Argument name to include in error message if `allow_empty = FALSE`. |
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.
This should mention errors in general, as it might be used more generally in the future.
Should also reference it's for expr
, and that it can be set to "..."
if called with expr = c(...)
.
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.
Since you use .or
, mention this can be a character vector of argument names?
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.
ideally, it should never resolve to being multiple arguments. Since before
and after
being both supplied should result in another error message.. (can't supply after
and before
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.
oh yeah, makes sense!
@@ -105,6 +105,14 @@ test_that("can forbid empty selections", { | |||
}) | |||
}) | |||
|
|||
test_that("can forbid empty selections with informative error", { |
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.
Need relocation tests as well?
Change class of error message Use new comment.
Added the argument to Edit: See also https://github.com/tidyverse/tidyr/pull/1549/files where I attempted to use this! I think a few packages will benefit from this once released to CRAN. |
Thank you! |
Closes #347
basically implement what was raised in #282 (comment)
Addresses part of #327
I have to say this fix is a bit naive and narrow and lacks a more general view.
Created on 2024-04-25 with reprex v2.1.0
Would it make sense to recognize it in
eval_relocate()
?A version I had locally had
error_arg = c(before_arg, after_arg)
, but couldn't tell if it was useful.This implementation doesn't change the default, which mean it is opt-in.
Reason behind.
I was working on gt and discovered
allow_empty
and I thought I'd use it to throw messages, (without having to rethrow it again)But I found that the error message Can't select empty items was not informative at all, so it is required to rethrow it or make tweaks in tidyselect.
So I thought it would be great if tidyselect had a mechanism to do this, and discovered it was proposed last time tidyselect was updated, but was never implemented.