tests/testthat/test-freq_subset.R

library(tibble)
library(haven)

test_that("subset will filter records as expected", {
  mtcars2 <- mtcars %>%
    rownames_to_column(var = "USUBJID") %>%
    mutate(am = factor(am), cyl = factor(cyl), gear = factor(gear))

  mtcars3 <- freq(mtcars2, colvar = "am", rowvar = "cyl", subset = gear == 4, statlist = statlist("n (x.x%)"))

  expect_equal(mtcars3[["0"]], c("2 (10.5%)", "2 (10.5%)", "0"), ignore_attr = TRUE)
})

Try the tidytlg package in your browser

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

tidytlg documentation built on Dec. 19, 2025, 9:07 a.m.