Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
markfairbanks committed Oct 14, 2022
1 parent 5d24d16 commit a16f1e2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/testthat/test-step-call-pivot_longer.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,32 @@ test_that("informative errors on unsupported features", {

})

test_that("can pivot all cols to long", {
tbl <- tibble(x = 1:2, y = 3:4)
dt <- lazy_dt(tbl, "DT")
step <- pivot_longer(dt, x:y)
out <- collect(step)

expect_equal(
show_query(step),
expr(melt(DT, measure.vars = !!c("x", "y"), variable.name = "name",
variable.factor = FALSE))
)
expect_equal(step$vars, c("name", "value"))
expect_equal(out$name, c("x", "x", "y", "y"))
expect_equal(out$value, c(1, 2, 3, 4))
})

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

res <- lazy_dt(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"))
})

0 comments on commit a16f1e2

Please sign in to comment.