Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into theme_element_unit_…
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
Meghansaha committed Nov 25, 2024
2 parents cefe843 + 2a05ed9 commit 74514f5
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 11 deletions.
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.9000
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ S3method(glance_fun_s3,default)
S3method(glance_fun_s3,mira)
S3method(global_pvalue_fun,default)
S3method(global_pvalue_fun,geeglm)
S3method(global_pvalue_fun,tidycrr)
S3method(inline_text,gtsummary)
S3method(inline_text,tbl_continuous)
S3method(inline_text,tbl_cross)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# gtsummary (development version)

* 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)

* Addressing encoding issue where `sort()` and `dplyr::arrange()` sorted differently, and the order of the `by` levels was inconsistent in the resulting table. (#2038)
Expand Down
2 changes: 1 addition & 1 deletion R/add_p.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ add_p <- function(x, ...) {
#' #### Specified neither `add_p(group)` nor `add_p(adj.vars)`
#'
#' - `"wilcox.test"` when `by` variable has two levels and variable is continuous.
#' - `"krustkal.test"` when `by` variable has more than two levels and variable is continuous.
#' - `"kruskal.test"` when `by` variable has more than two levels and variable is continuous.
#' - `"chisq.test.no.correct"` for categorical variables with all expected cell counts >=5,
#' and `"fisher.test"` for categorical variables with any expected cell count <5.
#'
Expand Down
4 changes: 0 additions & 4 deletions R/global_pvalue_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,3 @@ global_pvalue_fun.geeglm <- function(x, type, ...) {

cardx::ard_aod_wald_test(x, ...)
}

#' @rdname global_pvalue_fun
#' @export
global_pvalue_fun.tidycrr <- global_pvalue_fun.geeglm
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
2 changes: 1 addition & 1 deletion man/add_p.tbl_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/global_pvalue_fun.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

0 comments on commit 74514f5

Please sign in to comment.