tests/testthat/test-getcols.R

test_that("error", {
  expect_error(getcols())
  expect_null(getcols(mtcars))
  expect_error(getcols(mtcars, 100))
  expect_error(getcols(mtcars, "no"))
  expect_error(getcols(mtcars, no))
})


test_that("basic", {
  expect_equal(getcols(mtcars, 1), "mpg")
  expect_equal(getcols(mtcars, 1L), "mpg")
  expect_equal(getcols(mtcars, "mpg"), "mpg")
  expect_equal(getcols(mtcars, mpg), "mpg")
  expect_equal(getcols(mtcars, 1:2), c("mpg", "cyl"))
  
  m <- "mpg"
  expect_equal(getcols(mtcars, !!m), "mpg")
})

Try the faux package in your browser

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

faux documentation built on April 20, 2023, 9:13 a.m.