tests/testthat/test-tab.R

test_that("tab creates a publication table object", {
  set.seed(1)
  d <- data.frame(
    age = rnorm(80, 45, 12),
    sex = factor(sample(c("Female", "Male"), 80, TRUE)),
    outcome = factor(sample(c("No", "Yes"), 80, TRUE))
  )
  z <- tab(d, vars = vars(c.age, b2.sex), by = outcome,
           test = TRUE, show = FALSE)
  expect_s3_class(z, "r4vn_tab")
  expect_true(is.data.frame(z$data))
  expect_true(file.exists(z$file))
})

test_that("tabexport returns flat data", {
  set.seed(2)
  d <- data.frame(age = rnorm(40), sex = factor(sample(c("F", "M"), 40, TRUE)))
  z <- tab(d, vars = vars(c.age, sex), show = FALSE)
  out <- tabexport(z)
  expect_true(is.data.frame(out))
})

Try the R4VN package in your browser

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

R4VN documentation built on Sept. 30, 2026, 5:13 p.m.