tests/testthat/test-rename_dt.R

test_that("rename columns", {
  ir = as.data.table(iris)
  expect_equal(
    iris %>%
      rename_dt(sl = Sepal.Length,sw = Sepal.Width) ,
    setnames(copy(ir),old = 1:2,new = c("sl","sw"))
  )

  expect_equal(
    iris %>% rename_with_dt(toupper),
    copy(ir) %>% setnames(old = names(ir),new = names(ir) %>% toupper())
  )

  expect_equal(
    iris %>% rename_with_dt(toupper,"^Pe"),
    copy(ir) %>% setnames(old = 3:4,new = names(iris)[3:4] %>% toupper())
  )

})

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.