tests/testthat/test-add_overall.tbl_custom_summary.R

skip_on_cran()
skip_if_not(is_pkg_installed("withr", reference_pkg = "gtsummary"))

test_that("add_overall.tbl_custom_summary() works", {
  withr::local_options(list(width = 120))

  my_stats <- function(data, ...) {
    dplyr::tibble(
      marker_sum = sum(data$marker, na.rm = TRUE)
    )
  }
  expect_snapshot(
    trial |>
      tbl_custom_summary(
        include = c("stage", "grade"),
        by = "trt",
        stat_fns = everything() ~ my_stats,
        type = everything() ~ "continuous2", #new
        statistic = everything() ~ "S: {marker_sum}"
      ) |>
      add_overall() |>
      as.data.frame()
  )
})

Try the gtsummary package in your browser

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

gtsummary documentation built on Oct. 5, 2024, 1:06 a.m.