From 501a27cf4f4921af74b13f2e2a753bcbc7886be1 Mon Sep 17 00:00:00 2001 From: Lionel Henry Date: Fri, 25 Oct 2024 10:23:56 +0200 Subject: [PATCH] Always pass a string to `cli_abort()` --- R/eval-walk.R | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/R/eval-walk.R b/R/eval-walk.R index b2b7551..942773a 100644 --- a/R/eval-walk.R +++ b/R/eval-walk.R @@ -108,19 +108,24 @@ ensure_named <- function(pos, error_arg = NULL, call = caller_env()) { check_empty(pos, allow_empty, error_arg, call = call) - if (!allow_rename && any(names2(pos) != "")) { - msg <- "Can't rename variables in this context." - # Add more context if error_arg is supplied. - if (!is.null(error_arg)) { - msg <- c(msg, "i" = "{.arg {error_arg}} can't be renamed.") + if (is.null(error_arg)) { + cli::cli_abort( + "Can't rename variables in this context.", + class = "tidyselect:::error_disallowed_rename", + call = call + ) + } else { + cli::cli_abort( + c( + "Can't rename variables in this context.", + i = "{.arg {error_arg}} can't be renamed." + ), + class = "tidyselect:::error_disallowed_rename", + call = call + ) } - cli::cli_abort( - msg, - class = "tidyselect:::error_disallowed_rename", - call = call - ) } nms <- names(pos) <- names2(pos)