diff --git a/DESCRIPTION b/DESCRIPTION index 6d5c0f0..d287e07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,5 +38,5 @@ ByteCompile: true Config/Needs/website: tidyverse/tidytemplate Config/testthat/edition: 3 Encoding: UTF-8 -RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.2 diff --git a/R/eval-relocate.R b/R/eval-relocate.R index 4d7e8fe..29a9616 100644 --- a/R/eval-relocate.R +++ b/R/eval-relocate.R @@ -77,6 +77,13 @@ eval_relocate <- function(expr, allow_predicates <- allow_predicates && tidyselect_data_has_predicates(data) data <- tidyselect_data_proxy(data) + error_arg <- NULL + if (!is.null(before)) { + error_arg <- before_arg + } + if (!is.null(after)) { + error_arg <- c(error_arg, after_arg) + } expr <- as_quosure(expr, env = env) sel <- eval_select_impl( x = data, @@ -88,7 +95,7 @@ eval_relocate <- function(expr, allow_empty = allow_empty, allow_predicates = allow_predicates, type = "relocate", - error_arg = c(before_arg, after_arg), + error_arg = error_arg, error_call = error_call ) diff --git a/R/eval-select.R b/R/eval-select.R index d25d91d..fa82c61 100644 --- a/R/eval-select.R +++ b/R/eval-select.R @@ -43,8 +43,9 @@ #' use predicates (i.e. in `where()`). If `FALSE`, will error if `expr` uses a #' predicate. Will automatically be set to `FALSE` if `data` does not #' support predicates (as determined by [tidyselect_data_has_predicates()]). -#' @param error_arg Argument name to include in error message if `allow_empty = FALSE`. -#' Will give a better error message if the selection ends up empty. +#' @param error_arg Argument names for `expr`. These +#' are used in error messages. (You can use `"..."` if `expr = c(...)`). +#' For now, this is used when `allow_empty = FALSE`. #' @inheritParams rlang::args_dots_empty #' #' @return A named vector of numeric locations, one for each of the diff --git a/man/eval_select.Rd b/man/eval_select.Rd index 33f9ec8..19d85b0 100644 --- a/man/eval_select.Rd +++ b/man/eval_select.Rd @@ -76,8 +76,9 @@ is useful to implement purely selective behaviour.} in an empty selection. If \code{FALSE}, will error if \code{expr} yields an empty selection.} -\item{error_arg}{Argument name to include in error message if \code{allow_empty = FALSE}. -Will give a better error message if the selection ends up empty.} +\item{error_arg}{Argument names for \code{expr}. These +are used in error messages. (You can use \code{"..."} if \code{expr = c(...)}). +For now, this is used when \code{allow_empty = FALSE}.} } \value{ A named vector of numeric locations, one for each of the diff --git a/tests/testthat/_snaps/eval-relocate.md b/tests/testthat/_snaps/eval-relocate.md index 7dfaa7f..f4d6700 100644 --- a/tests/testthat/_snaps/eval-relocate.md +++ b/tests/testthat/_snaps/eval-relocate.md @@ -103,15 +103,13 @@ --- Code - (expect_error(relocate_loc(mtcars, before = integer(), allow_empty = FALSE))) - Output - + relocate_loc(mtcars, before = integer(), allow_empty = FALSE) + Condition Error in `relocate_loc()`: ! `before` and `after` must select at least one column. Code - (expect_error(relocate_loc(mtcars, starts_with("z"), allow_empty = FALSE))) - Output - + relocate_loc(mtcars, starts_with("z"), allow_empty = FALSE) + Condition Error in `relocate_loc()`: ! `before` and `after` must select at least one column. diff --git a/tests/testthat/test-eval-relocate.R b/tests/testthat/test-eval-relocate.R index ceb3833..d1f6dc8 100644 --- a/tests/testthat/test-eval-relocate.R +++ b/tests/testthat/test-eval-relocate.R @@ -186,10 +186,11 @@ test_that("can forbid empty selections", { test_that("can forbid empty selections", { x <- c(a = 1, b = 2, c = 3) - expect_snapshot({ - (expect_error(relocate_loc(mtcars, before = integer(), allow_empty = FALSE))) - (expect_error(relocate_loc(mtcars, starts_with("z"), allow_empty = FALSE))) - }) + expect_snapshot( + error = TRUE, { + relocate_loc(mtcars, before = integer(), allow_empty = FALSE) + relocate_loc(mtcars, starts_with("z"), allow_empty = FALSE) + }, cnd_class = TRUE) })