From d1552ed3dd9abecceabaa549c5c81360b2d7c5ce Mon Sep 17 00:00:00 2001 From: cathariv Date: Mon, 21 Oct 2024 13:50:31 -0400 Subject: [PATCH 1/3] adding jama styling to tbl_svysummary() --- R/theme_gtsummary.R | 13 +++++++++++++ tests/testthat/_snaps/theme_gtsummary.md | 14 ++++++++++++++ tests/testthat/test-theme_gtsummary.R | 17 +++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/R/theme_gtsummary.R b/R/theme_gtsummary.R index 0c63c5b3e7..1db9f148cd 100644 --- a/R/theme_gtsummary.R +++ b/R/theme_gtsummary.R @@ -84,6 +84,8 @@ theme_gtsummary_journal <- function(journal = c("jama", "lancet", "nejm", "qjeco "add_stat_label-arg:location" = "row", "tbl_summary-arg:statistic" = list(all_continuous() ~ "{median} ({p25} \U2013 {p75})", all_categorical() ~ "{n} ({p})"), + "tbl_svysummary-arg:statistic" = list(all_continuous() ~ "{median} ({p25} \U2013 {p75})", + all_categorical() ~ "{n} ({p})"), "tbl_summary-fn:addnl-fn-to-run" = function(x) { add_stat_label(x) |> modify_table_body( @@ -95,6 +97,17 @@ theme_gtsummary_journal <- function(journal = c("jama", "lancet", "nejm", "qjeco } ) }, + "tbl_svysummary-fn:addnl-fn-to-run" = function(x) { + add_stat_label(x) |> + modify_table_body( + \(x) { + if ("stat_label" %in% names(x)) { + x$stat_label <- gsub("Q1 \U2013 Q3", "IQR", x = x$stat_label) + } + x + } + ) + }, "add_difference-fn:addnl-fn-to-run" = function(x) { # merging coef and CI columns, if error, returning x unaltered tryCatch( diff --git a/tests/testthat/_snaps/theme_gtsummary.md b/tests/testthat/_snaps/theme_gtsummary.md index a6a101aabf..aba90b4d27 100644 --- a/tests/testthat/_snaps/theme_gtsummary.md +++ b/tests/testthat/_snaps/theme_gtsummary.md @@ -70,6 +70,20 @@ **Characteristic** **Beta** **(95% CI)** **p-value** 1 am -33 (-83 to 16) 0.18 +--- + + Code + with_gtsummary_theme(theme_gtsummary_journal("jama"), expr = as.data.frame( + modify_column_hide(add_difference(tbl_svysummary(svy_trial, by = trt, + include = age, label = age ~ "Age", missing = "no")), c("stat_2")))) + Message + Setting theme "JAMA" + Output + **Characteristic** **Drug A** \nN = 98 **Difference** **(****95% CI****)** + 1 Age, Median (IQR) 46 (37 – 60) 0.44 (-3.7 to 4.6) + **p-value** + 1 0.83 + # theme_gtsummary_journal('qjecon') works Code diff --git a/tests/testthat/test-theme_gtsummary.R b/tests/testthat/test-theme_gtsummary.R index 28a7841cd2..6273efaccc 100644 --- a/tests/testthat/test-theme_gtsummary.R +++ b/tests/testthat/test-theme_gtsummary.R @@ -233,6 +233,23 @@ test_that("theme_gtsummary_journal('jama') works", { ), "-33 (95% CI -83, 16; p=0.18)" ) + + svy_trial <- survey::svydesign(~1, data = trial, weights = ~1) + # check that we get + # - IQR separated with emdash in table + # - pvalues are rounded to 2 places + # - CI separator is " to " + # - estimate and CI are in the same cell with appropriate header + expect_snapshot( + with_gtsummary_theme( + theme_gtsummary_journal("jama"), + expr = svy_trial |> + tbl_svysummary(by = trt, include = age, label = age ~ "Age", missing = "no") |> + add_difference() |> + modify_column_hide(c("stat_2"))|> + as.data.frame() + ) + ) }) test_that("theme_gtsummary_journal('qjecon') works", { From 2040b13bd31c0c8b5c0f46c7ad00f5c0ffad30a5 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 21 Oct 2024 13:08:00 -0700 Subject: [PATCH 2/3] bump version number --- DESCRIPTION | 2 +- NEWS.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 69c82a03fd..6079772285 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gtsummary Title: Presentation-Ready Data Summary and Analytic Result Tables -Version: 2.0.3.9002 +Version: 2.0.3.9003 Authors@R: c( person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0862-2018")), diff --git a/NEWS.md b/NEWS.md index 5c0cfb0401..3b783a8143 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # gtsummary (development version) -* Removed `global_pvalue_fun_tidycrr()` as already been migrated to the {tidycmprsk} package. (#1997) +* Updated the styling function to style tbl_svysummary() tables with JAMA theme. (#1964; @vjcatharine) + +* Removed `global_pvalue_fun.tidycrr()` as already been migrated to the {tidycmprsk} package. (#1997; @jwoolfolk) * Bug fix in `add_ci.tbl_svysummary()` for factor variables where order was alphabetical instead of the factor levels. (#2036) From 315d88c1809e348784cefe7b45f164936c469687 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Mon, 21 Oct 2024 13:09:40 -0700 Subject: [PATCH 3/3] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3b783a8143..214c269ec0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # gtsummary (development version) -* Updated the styling function to style tbl_svysummary() tables with JAMA theme. (#1964; @vjcatharine) +* Updated the `theme_gtsummary_journal("jama")` theme to apply changes to `tbl_svysummary()`. (#1964; @vjcatharine) * Removed `global_pvalue_fun.tidycrr()` as already been migrated to the {tidycmprsk} package. (#1997; @jwoolfolk)