tests/testthat/test_catch_asNumericIfPossible.R

### set up test vectors
num <- 3:1
char_num <- c("3", "4", "5")
char_char <- c("a", "b", "d")
char_mixed <- c("la", "le", "1")
fac_num <- as.factor(char_num)
fac_mixed <- as.factor(char_mixed)
fac_char <- as.factor(char_char)

test_that("Numeric vector", {
  expect_equal(catch_asNumericIfPossible(num, warn = "hallo"), num)
  expect_warning(catch_asNumericIfPossible(char_char, warn = "hallo"), "hallo")
})

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.