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"))
  )

})

Try the tidyfst package in your browser

Any scripts or data that you put into this service are public.

tidyfst documentation built on Sept. 16, 2024, 9:06 a.m.