diff --git a/NEWS.md b/NEWS.md index aa72cff08..688678abb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ BREAKING CHANGES AND DEPRECATIONS - argument `pattern` is deprecated. Use `select` instead. - argument `safe` is deprecated. The function now errors when `select` contains unknown column names. + - when `replacement` is `NULL`, an error is now thrown (previously, column + indices were used as new names). CHANGES diff --git a/R/data_rename.R b/R/data_rename.R index 622200c27..138a1bb91 100644 --- a/R/data_rename.R +++ b/R/data_rename.R @@ -12,7 +12,6 @@ #' @param replacement Character vector. Can be one of the following: #' - A character vector that indicates the new names of the columns selected #' in `select`. `select` and `replacement` must be of the same length. -#' - `NULL`, in which case columns are numbered in sequential order. #' - A string (i.e. character vector of length 1) with a "glue" styled #' pattern. Currently supported tokens are: #' - `{col}` which will be replaced by the column name, i.e. the @@ -117,11 +116,6 @@ data_rename <- function(data, replacement <- names(select) } - # name columns 1, 2, 3 etc. if no replacement - if (is.null(replacement)) { - replacement <- paste0(seq_along(select)) - } - # coerce to character replacement <- as.character(replacement) diff --git a/man/data_rename.Rd b/man/data_rename.Rd index 0e0d8a9a4..0ca627cf6 100644 --- a/man/data_rename.Rd +++ b/man/data_rename.Rd @@ -59,7 +59,6 @@ will just return \code{"Species"}.} \itemize{ \item A character vector that indicates the new names of the columns selected in \code{select}. \code{select} and \code{replacement} must be of the same length. -\item \code{NULL}, in which case columns are numbered in sequential order. \item A string (i.e. character vector of length 1) with a "glue" styled pattern. Currently supported tokens are: \itemize{ diff --git a/tests/testthat/test-data_rename.R b/tests/testthat/test-data_rename.R index 4681c9259..6abc7d23f 100644 --- a/tests/testthat/test-data_rename.R +++ b/tests/testthat/test-data_rename.R @@ -53,10 +53,11 @@ test_that("data_rename: replacement not allowed to have NA or empty strings", { # replacement ------------- -test_that("data_rename uses indices when no replacement", { - x <- data_rename(test, select = c("Sepal.Length", "Petal.Length")) - expect_identical(dim(test), dim(x)) - expect_named(x, c("1", "Sepal.Width", "2", "Petal.Width", "Species")) +test_that("data_rename errors when no replacement", { + expect_error( + data_rename(test, select = c("Sepal.Length", "Petal.Length")), + "There are more names in `select` than in `replacement`" + ) }) test_that("data_rename errors when too many names in 'replacement'", {