tests/testthat/test-separate.R

test_that("separate a column", {
  df <- data.table(x = c(NA, "a.b", "a.d", "b.c"))

  expect_equal(
    df %>% separate_dt(x, c("A", "B")),
    data.table(A=c(NA,"a","a","b"),B=c(NA,"b","d","c"))
  )

  expect_equal(
    df %>% separate_dt(x, c("A", "B")),
    df %>% separate_dt("x", c("A", "B"))
  )

  expect_equal(
    df %>% separate_dt(x,into = c(NA,"B")),
    data.table(B=c(NA,"b","d","c"))
  )
})

Try the tidyfst package in your browser

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

tidyfst documentation built on July 26, 2023, 5:20 p.m.