tests/testthat/test_insert.col.R

test_that("Errors", {
  expect_error(insert.col(1),
               "'dat' is neither a 'data.frame', 'tibble' or 'data.table' object.")
})

###
test_that("Insert one column in data.frame by name", {
  out <- insert.col(mtcars, toinsert = "mpg", after = "carb")
  expect_equal(out, mtcars[, c(2:11, 1)])

  out <- insert.col(mtcars, toinsert = "mpg", after = "cyl")
  expect_equal(out, mtcars[, c(2, 1, 3:11)])
})

###
test_that("Insert one column in data.table by name", {
  mtcars_table <- as.data.table(mtcars)
  suppressMessages(out <- insert.col(mtcars_table, toinsert = "mpg", after = "carb"))

  mtcars2 <- mtcars
  rownames(mtcars2) <- NULL
  expect_equal(out, mtcars2[, c(2:11, 1)])
})

Try the eatTools package in your browser

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

eatTools documentation built on Nov. 23, 2023, 5:06 p.m.