tests/testthat/test-tab-percentage-examples.R

test_that("documented tab percentage calls are mutually exclusive", {
  set.seed(2026)
  d <- data.frame(
    sex = factor(sample(c("Female", "Male"), 80, TRUE)),
    smoking = factor(sample(c("No", "Yes"), 80, TRUE)),
    outcome = factor(sample(c("No", "Yes"), 80, TRUE))
  )

  expect_no_error(tab(
    d, vars = vars(sex, smoking), by = outcome,
    row = TRUE, col = FALSE, cell = FALSE, show = FALSE
  ))

  expect_no_error(tab(
    d, vars = vars(sex, smoking), by = outcome,
    row = FALSE, col = TRUE, cell = FALSE, show = FALSE
  ))

  expect_no_error(tab(
    d, vars = vars(sex, smoking), by = outcome,
    row = FALSE, col = FALSE, cell = TRUE, show = FALSE
  ))
})

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.