tests/testthat/test-function-callWithStringsAsFactors.R

test_that("callWithStringsAsFactors() works", {

  get_stringsAsFactors <- function() getOption("stringsAsFactors")
  
  option_bak <- get_stringsAsFactors()

  d1 <- callWithStringsAsFactors(TRUE, get_stringsAsFactors)
  expect_identical(d1, TRUE)
  expect_identical(option_bak, get_stringsAsFactors())
  
  d2 <- callWithStringsAsFactors(FALSE, get_stringsAsFactors)
  expect_identical(d2, FALSE)
  expect_identical(option_bak, get_stringsAsFactors())

  expect_error(callWithStringsAsFactors(1, data.frame, a = "x"))
})
KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.