From faacd32d7932ff30372b57d17a596d3f1218f52a Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Mon, 6 Nov 2023 08:51:40 -0500 Subject: [PATCH] Add tests to ensure `across()` allows tidyselect renaming (#6953) --- tests/testthat/test-across.R | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/testthat/test-across.R b/tests/testthat/test-across.R index eedc69a056..c644669a11 100644 --- a/tests/testthat/test-across.R +++ b/tests/testthat/test-across.R @@ -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)