tests/testthat/test-distinct_dt.R

test_that("distinct_dt", {

  ir = as.data.table(iris)
  mt = as.data.table(mtcars)

  expect_equal(
    iris %>% distinct_dt(),
    unique(ir)
  )

  expect_equal(
    iris %>% distinct_dt(Species),
    unique(ir[,"Species"])
  )

  expect_equal(
    iris %>% distinct_dt(Species,.keep_all = TRUE),
    unique(ir,by = "Species")
  )

  expect_equal(
    mtcars %>% distinct_dt(cyl,vs),
    unique(mt[,c("cyl","vs")])
  )

  expect_equal(
    mtcars %>% distinct_dt(cyl,vs,.keep_all = TRUE),
    unique(mt,by = c("cyl","vs"))
  )

})
hope-data-science/tidyfst documentation built on Sept. 23, 2024, 8:05 p.m.