tests/testthat/test_1-0-0_select_which.R

context("select_which")

test_that("Returns correct columns", {
  library(data.table)
  DT <- data.table(x = 1:5,
                   y = letters[1:5],
                   AB = c(NA, TRUE, FALSE, TRUE, FALSE))
  out <- select_which(DT, is.numeric)
  expect_equal(names(out), "x")
  out <- select_which(DT, anyNA, .and.dots = "y")
  expect_equal(names(out), c("AB", "y"))
  
  expect_error(select_which(data.frame(x = 1), checkDT = TRUE), regexp = "must be a data.table")
})

test_that("Returns correct columns when .and.dots not char", {
  library(data.table)
  DT <- data.table(x = 1:5,
                   y = letters[1:5],
                   AB = c(NA, TRUE, FALSE, TRUE, FALSE))
  out <- select_which(DT, anyNA, .and.dots = 2)
  expect_equal(names(out), c("AB", "y"))
})

Try the hutils package in your browser

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

hutils documentation built on April 13, 2022, 5:23 p.m.