diff --git a/R/data_rename.R b/R/data_rename.R index 71edd7b6b..93d32d612 100644 --- a/R/data_rename.R +++ b/R/data_rename.R @@ -56,9 +56,6 @@ #' # use named vector to rename #' head(data_rename(iris, c(length = "Sepal.Length", width = "Sepal.Width"))) #' -#' # Reset names -#' head(data_rename(iris, NULL)) -#' #' # Change all #' head(data_rename(iris, replacement = paste0("Var", 1:5))) #' @@ -92,8 +89,12 @@ data_rename <- function(data, verbose = TRUE, pattern = NULL, ...) { + # If the user does data_rename(iris, pattern = "Sepal.Length", "length"), + # then "length" is matched to select by position while it's the replacement + # => do the switch manually if (!is.null(pattern)) { .is_deprecated("pattern", "select") + replacement <- select select <- pattern } if (isFALSE(safe)) { diff --git a/man/data_rename.Rd b/man/data_rename.Rd index 0ca627cf6..8d99fb54f 100644 --- a/man/data_rename.Rd +++ b/man/data_rename.Rd @@ -122,9 +122,6 @@ head(data_rename(iris, "Sepal.Length", "length")) # use named vector to rename head(data_rename(iris, c(length = "Sepal.Length", width = "Sepal.Width"))) -# Reset names -head(data_rename(iris, NULL)) - # Change all head(data_rename(iris, replacement = paste0("Var", 1:5))) diff --git a/tests/testthat/test-data_rename.R b/tests/testthat/test-data_rename.R index 3bc0254a8..3495a3355 100644 --- a/tests/testthat/test-data_rename.R +++ b/tests/testthat/test-data_rename.R @@ -80,16 +80,11 @@ test_that("data_rename works when not enough names in 'replacement'", { # no select -------------- -test_that("data_rename uses the whole dataset when select = NULL", { - x1 <- data_rename(test) - x2 <- data_rename(test, select = names(test)) - expect_identical(dim(test), dim(x1)) - expect_identical(x1, x2) - - x3 <- data_rename(test, replacement = paste0("foo", 1:5)) - x4 <- data_rename(test, select = names(test), replacement = paste0("foo", 1:5)) - expect_identical(dim(test), dim(x3)) - expect_identical(x3, x4) +test_that("data_rename errors when select = NULL", { + expect_error( + data_rename(test), + "more names in `select`" + ) }) @@ -98,7 +93,7 @@ test_that("data_rename uses the whole dataset when select = NULL", { test_that("data_rename: argument 'safe' is deprecated", { expect_error( data_rename(iris, "FakeCol", "length", verbose = FALSE), - "more names in `replacement`" + "were not found" ) expect_error( expect_warning( @@ -117,13 +112,6 @@ test_that("data_rename deals correctly with duplicated replacement", { expect_named(x[1:4], c("foo", "bar", "foo.2", "bar.2")) }) -test_that("data_rename errors if invalid select", { - expect_error( - data_rename(iris, "FakeCol", "length", verbose = FALSE), - "more names in `replacement`" - ) -}) - # preserve attributes --------------------------