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

Bug fix in add_overall.tbl_custom_summary() #2028

Merged
merged 4 commits into from
Oct 4, 2024
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# gtsummary (development version)

* Bug fix in `add_overall.tbl_custom_summary()` due to extraneous arguments being passed to primary function. (#2027)

* Added function `tbl_hierarchical()`, `tbl_hierarchical_count()`, `tbl_ard_hierarchical()`, `brdg_hierarchical()`, and `pier_summary_hierarchical()`. Consider these functions as a preview. We will be making changes without the full deprecation cycle in the coming releases. (#1872)

* Adding the `style_*(prefix, suffix)` and `label_style_*(prefix, suffix)` for adding a string before or after the formatted results. These arguments have not been added to the p-value formatting functions. (#1690)
Expand Down
1 change: 1 addition & 0 deletions R/tbl_custom_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ tbl_custom_summary <- function(data,
# will return call, and all object passed to in tbl_summary call -------------
# the object func_inputs is a list of every object passed to the function
tbl_custom_summary_inputs <- as.list(environment())
tbl_custom_summary_inputs[["default_types"]] <- NULL
call <- match.call()


Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/add_overall.tbl_custom_summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# add_overall.tbl_custom_summary() works

Code
as.data.frame(add_overall(tbl_custom_summary(trial, include = c("stage", "grade"), by = "trt", stat_fns = everything() ~
my_stats, type = everything() ~ "continuous2", statistic = everything() ~ "S: {marker_sum}")))
Output
**Characteristic** **Overall** \nN = 200 **Drug A** \nN = 98 **Drug B** \nN = 102
1 T Stage <NA> <NA> <NA>
2 S: marker_sum S: 174 S: 94 S: 80
3 Grade <NA> <NA> <NA>
4 S: marker_sum S: 174 S: 94 S: 80

24 changes: 24 additions & 0 deletions tests/testthat/test-add_overall.tbl_custom_summary.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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()
)
})