tests/testthat/test-mutate_dt.R

test_that("mutate and transmute", {

   ir = as.data.table(iris)

  expect_equal(
    iris %>% mutate_dt(one = 1,Sepal.Length = Sepal.Length + 1),
    copy(ir)[,`:=`(one = 1,Sepal.Length = Sepal.Length + 1)]
  )

  expect_equal(
    iris %>% mutate_dt(id = 1:.N,grp = .GRP,by = Species),
    copy(ir)[,`:=`(id = 1:.N,grp = .GRP),by = Species]
  )

  expect_equal(
    iris %>% transmute_dt(one = 1,Sepal.Length = Sepal.Length + 1),
    ir[,.(one = 1,Sepal.Length = Sepal.Length + 1)]
  )

})

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.