Skip to content

Commit

Permalink
Add tests to ensure across() allows tidyselect renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Nov 3, 2023
1 parent 81d0503 commit 50b2d69
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/testthat/test-across.R
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,29 @@ test_that("across() can access lexical scope (#5862)", {
)
})

test_that("across() allows renaming in `.cols` (#6895)", {
df <- tibble(x = 1, y = 2, z = 3)
cols <- set_names(c("x", "y"), c("a", "b"))

expect_identical(
mutate(df, across(all_of(cols), identity)),
mutate(df, a = x, b = y)
)
expect_identical(
mutate(df, (across(all_of(cols), identity))),
mutate(df, a = x, b = y)
)

expect_identical(
mutate(df, across(all_of(cols), identity, .names = "{.col}_name")),
mutate(df, a_name = x, b_name = y)
)
expect_identical(
mutate(df, (across(all_of(cols), identity, .names = "{.col}_name"))),
mutate(df, a_name = x, b_name = y)
)
})

test_that("if_any() and if_all() expansions deal with no inputs or single inputs", {
d <- data.frame(x = 1)

Expand Down

0 comments on commit 50b2d69

Please sign in to comment.