We know that a mismatch error is classed with a vctrs subscript oob error (as of the most recent update) and also stores the problematic selection in $i:
I fully acknowledge that these are not part of the official API, so I do not mean to build on top of this pattern. Instead, I was hoping that tidyselect could throw more specific, classed errors, where possible. For example, it'd be nice for an empty selection error with allow_empty = FALSE to look something like this:
I realize that this is a non-trivial ask that probably requires a lot of deliberation, but I was curious whether this is within scope / planned to be worked on. Thanks in advance for considering!
Geez I'm just seeing that #350 partially addresses this -- sorry for the noise. My issue is not a complete duplicate but pretty close, so please feel free to close this issue if you decide to merge that other PR.
A user's attempt at selecting a column can fail for various reasons - currently, there are some (extremely brittle) ways to infer what went wrong.
Briefly, if we wanted to distinguish between these three types of tidyselect errors (mismatch, other evaluation error, empty):
We know that a mismatch error is classed with a vctrs subscript oob error (as of the most recent update) and also stores the problematic selection in
$i
:An error from evaluating the user-supplied expression gets chained, so these errors are distinguished by having a
$parent
:Lastly, an empty selection that's promoted to an error with
allow_empty = FALSE
has neither$i
nor a$parent
:I fully acknowledge that these are not part of the official API, so I do not mean to build on top of this pattern. Instead, I was hoping that tidyselect could throw more specific, classed errors, where possible. For example, it'd be nice for an empty selection error with
allow_empty = FALSE
to look something like this:... by adding the
"tidyselect_error_*"
class where the error gets thrown:https://github.com/r-lib/tidyselect/blob/fd22cc1dc08bd67fd4501bfad9de67628a35e854/R/eval-walk.R#L128-L132
I realize that this is a non-trivial ask that probably requires a lot of deliberation, but I was curious whether this is within scope / planned to be worked on. Thanks in advance for considering!