Skip to content

Commit

Permalink
fix tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Dec 2, 2024
1 parent 5d00d9c commit 7dd89c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
7 changes: 4 additions & 3 deletions R/data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
#'
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions man/data_rename.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 6 additions & 18 deletions tests/testthat/test-data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
)
})


Expand All @@ -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(
Expand All @@ -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 --------------------------

Expand Down

0 comments on commit 7dd89c2

Please sign in to comment.