Skip to content

Commit

Permalink
actually, no longer need the with_rename_error wrapper?
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Oct 28, 2024
1 parent b08764c commit 8d84f61
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
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_cannot_rename` = function(cnd) {
cli::cli_abort(
"Can't rename variables when {.arg {arg}} is supplied.",
call = error_call
)
}
)
}
20 changes: 12 additions & 8 deletions tests/testthat/_snaps/eval-relocate.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,26 @@

Code
relocate_loc(x, b, before = c(new = c))
Condition <rlang_error>
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables when `before` is supplied.
! Can't rename variables in this context.
i In argument: `before`.
Code
relocate_loc(x, b, before = c(new = c), before_arg = ".before")
Condition <rlang_error>
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables when `.before` is supplied.
! Can't rename variables in this context.
i In argument: `.before`.
Code
relocate_loc(x, b, after = c(new = c))
Condition <rlang_error>
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables when `after` is supplied.
! Can't rename variables in this context.
i In argument: `after`.
Code
relocate_loc(x, b, after = c(new = c), after_arg = ".after")
Condition <rlang_error>
Condition <tidyselect_error_cannot_rename>
Error in `relocate_loc()`:
! Can't rename variables when `.after` is supplied.
! Can't rename variables in this context.
i In argument: `.after`.

0 comments on commit 8d84f61

Please sign in to comment.