tests/testthat/test-quick-summary.R

test_that("tab1 supports multiple variables and nested by", {
  d <- data.frame(
    sex = factor(rep(c("Female", "Male"), each = 4)),
    agegroup = factor(rep(c("<40", "40+"), 4)),
    smoking = factor(c("No", "Yes", "No", "Yes", "No", "No", "Yes", "Yes")),
    alcohol = factor(c("No", "No", "Yes", "Yes", "No", "Yes", "No", "Yes"))
  )
  usedf(d, quiet = TRUE)
  z <- tab1(smoking, alcohol, by = c(sex, agegroup), show = FALSE)
  expect_s3_class(z, "r4vn_quick")
  expect_equal(z$by, c("sex", "agegroup"))
  expect_equal(length(z$variables), 2L)
  expect_equal(length(z$variables[[1]]$strata), 4L)
  usedf(clear = TRUE, quiet = TRUE)
})

test_that("sum1 supports nested by and detail", {
  d <- data.frame(
    sex = factor(rep(c("Female", "Male"), each = 4)),
    agegroup = factor(rep(c("<40", "40+"), 4)),
    age = c(25, 42, 31, 55, 29, 48, 36, 61),
    bmi = c(20.1, 23.5, 21.7, 25.2, 22.4, 26.1, NA, 24.8)
  )
  usedf(d, quiet = TRUE)
  z <- sum1(age, bmi, by = c(sex, agegroup), detail = TRUE, show = FALSE)
  expect_s3_class(z, "r4vn_quick")
  expect_equal(z$by, c("sex", "agegroup"))
  expect_true("Skewness" %in% names(z$variables[[1]]$overall))
  usedf(clear = TRUE, quiet = TRUE)
})

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.