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

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