Skip to content

Commit

Permalink
Remove with_rename_error() wrapper (#369)
Browse files Browse the repository at this point in the history
And fix duplicate NEWS items
  • Loading branch information
olivroy authored Oct 28, 2024
1 parent f885116 commit a4b0758
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 39 deletions.
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`.

0 comments on commit a4b0758

Please sign in to comment.