Skip to content
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

fixup error msg #369

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
In addition, it gains a `cross` argument that allows you to take the
cartesian product of these arguments instead.

* `eval_select(allow_empty = FALSE)` gains a new argument to yield a better error
message in case of empty selection (@olivroy, #327)

* `eval_select()` and `eval_relocate()` gain a new `error_arg` argument that can be specified to throw a better error message when `allow_empty = FALSE`.

* `eval_select()` and `eval_relocate()` throw a classed error message when `allow_empty = FALSE` (@olivroy, #347).

# tidyselect 1.2.1
Expand Down
50 changes: 16 additions & 34 deletions R/eval-relocate.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,14 @@ eval_relocate <- function(expr,
}

if (has_before) {
where <- with_rename_errors(
eval_select(
expr = before,
data = data,
env = env,
error_call = error_call,
allow_predicates = allow_predicates,
allow_rename = FALSE
),
arg = before_arg,
error_call = error_call
where <- eval_select(
expr = before,
data = data,
env = env,
error_call = error_call,
allow_predicates = allow_predicates,
allow_rename = FALSE,
error_arg = before_arg
)
where <- unname(where)

Expand All @@ -138,17 +135,14 @@ eval_relocate <- function(expr,
where <- min(where)
}
} else if (has_after) {
where <- with_rename_errors(
eval_select(
expr = after,
data = data,
env = env,
error_call = error_call,
allow_predicates = allow_predicates,
allow_rename = FALSE
),
arg = after_arg,
error_call = error_call
where <- eval_select(
expr = after,
data = data,
env = env,
error_call = error_call,
allow_predicates = allow_predicates,
allow_rename = FALSE,
error_arg = after_arg
)
where <- unname(where)

Expand Down Expand Up @@ -181,15 +175,3 @@ eval_relocate <- function(expr,

sel
}

with_rename_errors <- function(expr, arg, error_call) {
withCallingHandlers(
expr,
`tidyselect:::error_disallowed_rename` = function(cnd) {
cli::cli_abort(
"Can't rename variables when {.arg {arg}} is supplied.",
call = error_call
)
}
)
}
4 changes: 4 additions & 0 deletions tests/testthat/_snaps/eval-relocate.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,23 @@
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables in this context.
i In argument: `before`.
Code
relocate_loc(x, b, before = c(new = c), before_arg = ".before")
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables in this context.
i In argument: `.before`.
Code
relocate_loc(x, b, after = c(new = c))
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables in this context.
i In argument: `after`.
Code
relocate_loc(x, b, after = c(new = c), after_arg = ".after")
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables in this context.
i In argument: `.after`.

Loading