tests/testthat/test-titles.R

library(tibble)
test_that("titles_file addes titles as expected", {
  withr::with_options(list(tidytlg.add_datetime = FALSE), {
    mtcars2 <- mtcars %>%
      rownames_to_column(var = "USUBJID") %>%
      mutate(am = factor(am), cyl = factor(cyl), gear = factor(gear))

    tab <- freq(mtcars2, colvar = "cyl", rowvar = "am")

    withr::with_dir(
      new = test_path("test_outputs"),
      code = {
        gentlg(tab, file = "TSIDEM01", title_file = "titles.xls", colheader = c("label", "4", "6", "8"))
      }
    )

    withr::with_dir(
      new = test_path("test_outputs"),
      code = {
        gentlg(tab, file = "GSVIT01A", title_file = "titles.xls", colheader = c("label", "4", "6", "8"))
      }
    )
    expect_snapshot_file(test_path("test_outputs/gsvit01a.rtf"))
  })
})

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.