tests/testthat/test-relocate_dt.R

test_that("relocate columns", {
  df <- data.table(a = 1, b = 1, c = 1, d = "a", e = "a", f = "a")

  expect_equal(
    df %>% relocate_dt(f),
    data.table(f = "a",a = 1, b = 1, c = 1, d = "a", e = "a")
  )

  expect_equal(
    df %>% relocate_dt(a,how = "last"),
    data.table(b = 1, c = 1, d = "a", e = "a", f = "a",a = 1)
  )

  expect_equal(
    df %>% relocate_dt(is.character),
    data.table(d = "a", e = "a", f = "a",a = 1, b = 1, c = 1)
  )

  expect_equal(
    df %>% relocate_dt(is.numeric, how = "last"),
    data.table(d = "a", e = "a", f = "a",a = 1, b = 1, c = 1)
  )

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