Skip to content

Commit

Permalink
More tests for NA column names
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Oct 21, 2022
1 parent f2d38dd commit 7f3761e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/testthat/test-step-call-pivot_wider.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ test_that("column with `...j` name can be used as `names_from`", {
expect_equal(nrow(pv), 1)
})

test_that("correctly handles columns named NA, #394", {
df <- lazy_dt(tibble(x = c("a", "a"), y = c("a", NA), z = 1:2))

res <- df %>%
pivot_wider(names_from = y,
values_from = z,
names_glue = "{y}_new",
names_repair = "minimal") %>%
collect()
expect_named(res, c("x", "NA_new", "a_new"))

res <- df %>%
pivot_wider(names_from = y,
values_from = z,
names_glue = "{y}",
names_repair = "minimal") %>%
collect()
expect_named(res, c("x", "NA", "a"))

df <- lazy_dt(tibble(x = c('a', NA), y = 1:2))

res <- df %>%
pivot_wider(names_from = 'x', values_from = 'y') %>%
collect()
expect_named(res, c("NA", "a"))
})

# column names -------------------------------------------------------------

test_that("names_glue affects output names", {
Expand Down

0 comments on commit 7f3761e

Please sign in to comment.