Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding jama styling to tbl_svysummary() #2045

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-0862-2018")),
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# gtsummary (development version)

* Removed `global_pvalue_fun_tidycrr()` as already been migrated to the {tidycmprsk} package. (#1997)
* 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)

* Bug fix in `add_ci.tbl_svysummary()` for factor variables where order was alphabetical instead of the factor levels. (#2036)

Expand Down
13 changes: 13 additions & 0 deletions R/theme_gtsummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/theme_gtsummary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-theme_gtsummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Loading