Skip to content

Commit

Permalink
data_rename(): "Error: Following variable(s) were not found" in ver…
Browse files Browse the repository at this point in the history
…sion '0.13.0.17'

Fixes #571
  • Loading branch information
strengejacke committed Dec 13, 2024
1 parent 25f8ec4 commit f6bec45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
24 changes: 13 additions & 11 deletions R/data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ data_rename <- function(data,
insight::format_warning("In `data_rename()`, argument `safe` is no longer used and will be removed in a future release.") # nolint
}

# change all names if no pattern specified
select <- .select_nse(
select,
data,
exclude = NULL,
ignore_case = NULL,
regex = NULL,
allow_rename = TRUE,
verbose = verbose,
ifnotfound = "error"
)
# change all names if no pattern specified - this only works for data frames
if (!is.list(data) || is.data.frame(data)) {
select <- .select_nse(
select,
data,
exclude = NULL,
ignore_case = NULL,
regex = NULL,
allow_rename = TRUE,
verbose = verbose,
ifnotfound = "error"
)
}

# Forbid partially named "select",
# Ex: if select = c("foo" = "Species", "Sepal.Length") then the 2nd name and
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,13 @@ test_that("Argument `pattern` is deprecated", {
fixed = TRUE
)
})

test_that("works with lists", {
result <- list(
setosa.a = structure(data.frame(1)),
versicolor.a = structure(data.frame(2))
)
new_names <- c("setosa, a", "versicolor, a")
out <- data_rename(result, select = names(result), replacement = new_names)
expect_identical(names(out), new_names)
})

0 comments on commit f6bec45

Please sign in to comment.