Skip to content

Commit

Permalink
588 Add "Stratified by" Subtitles (#594)
Browse files Browse the repository at this point in the history
* Add subtitle to tm_g_forest_tte

* Add subtitle to tm_t_coxreg

* Add subtitle to tm_t_binary_outcome

* Update NEWS

* Update tests

* [skip actions] Restyle files

* [skip actions] Roxygen Man Pages Auto Update

* Fix test for tm_g_forest_tte

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 16, 2022
1 parent 697afbf commit 86f7f04
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* `tm_t_events_summary` now allows nested `arm_var` columns matching other outputs such as `tm_t_events`.
* Added validation in `tm_t_abnormality_by_worst_grade` when `arm_var` is not selected.
* Enhanced `tm_t_binary_outcome` to include all responders in the response table by default.
* Added a subtitle to `tm_g_forest_tte`, `tm_t_coxreg`, and `tm_t_binary_outcome` listing stratification factors.

### Bug fixes
* Fixed a bug to prevent processing of empty sets of data by `tm_g_forest_rsp.R` causing `shiny` errors during the runtime.
Expand Down
16 changes: 14 additions & 2 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ template_forest_tte <- function(dataname = "ANL",
all_ggplot2_args <- teal.widgets::resolve_ggplot2_args(
user_plot = ggplot2_args,
module_plot = teal.widgets::ggplot2_args(
labs = list(title = paste0("Forest plot of survival duration for ", obj_var_name), caption = "")
labs = list(
title = paste("Forest Plot of Survival Duration for", obj_var_name),
subtitle = ifelse(is.null(strata_var), "", paste("Stratified by", paste(strata_var, collapse = " and "))),
caption = ""
)
)
)

Expand All @@ -175,7 +179,15 @@ template_forest_tte <- function(dataname = "ANL",

plot_call <- substitute(
decorate_grob(p, titles = title, footnotes = caption, gp_footnotes = grid::gpar(fontsize = 12)),
env = list(title = all_ggplot2_args$labs$title, caption = all_ggplot2_args$labs$caption, p = plot_call)
env = list(
title = `if`(
all_ggplot2_args$labs$subtitle == "",
all_ggplot2_args$labs$title,
c(all_ggplot2_args$labs$title, all_ggplot2_args$labs$subtitle)
),
caption = all_ggplot2_args$labs$caption,
p = plot_call
)
)

plot_call <- substitute(
Expand Down
8 changes: 7 additions & 1 deletion R/tm_t_binary_outcome.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ template_binary_outcome <- function(dataname,
paste("Table of", paramcd, "for", responder_val, "Responders")
}

strata_var <- control$strat$strat
subtitle <- ifelse(length(strata_var) == 0, "", paste("Stratified by", paste(strata_var, collapse = " and ")))

parsed_basic_table_args <- teal.widgets::parse_basic_table_args(
teal.widgets::resolve_basic_table_args(
user_table = basic_table_args,
module_table = teal.widgets::basic_table_args(title = table_title)
module_table = teal.widgets::basic_table_args(
title = table_title,
subtitles = subtitle
)
)
)

Expand Down
19 changes: 14 additions & 5 deletions R/tm_t_coxreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template_coxreg_u <- function(dataname,
control = control_coxreg(),
append = FALSE,
basic_table_args = teal.widgets::basic_table_args(
title = paste0("Multi-Variable Cox Regression for ", paramcd)
title = paste("Multi-Variable Cox Regression for", paramcd)
)) {
y <- list()
ref_arm_val <- paste(ref_arm, collapse = "/")
Expand Down Expand Up @@ -972,12 +972,17 @@ srv_t_coxreg <- function(id,
ANL <- teal.code::chunks_get_var("ANL") # nolint
paramcd <- as.character(unique(ANL[[unlist(paramcd$filter)["vars_selected"]]]))
multivariate <- input$type == "Multivariate"
strata_var <- as.vector(anl_m$columns_source$strata_var)

if (input$type == "Multivariate") {
main_title <- paste0("Multi-Variable Cox Regression for ", paramcd)
main_title <- paste("Multi-Variable Cox Regression for", paramcd)
subtitle <- ifelse(length(strata_var) == 0, "", paste("Stratified by", paste(strata_var, collapse = " and ")))
all_basic_table_args <- teal.widgets::resolve_basic_table_args(
user_table = basic_table_args,
module_table = teal.widgets::basic_table_args(title = main_title)
module_table = teal.widgets::basic_table_args(
title = main_title,
subtitles = subtitle
)
)
expr <- call_template(unlist(input$buckets$Comp), anl_m, paramcd, multivariate, all_basic_table_args)
mapply(
Expand All @@ -988,10 +993,14 @@ srv_t_coxreg <- function(id,
teal.code::chunks_safe_eval()
teal.code::chunks_get_var("result")
} else {
main_title <- paste0("Cox Regression for ", paramcd)
main_title <- paste("Cox Regression for", paramcd)
subtitle <- ifelse(length(strata_var) == 0, "", paste("Stratified by", paste(strata_var, collapse = " and ")))
all_basic_table_args <- teal.widgets::resolve_basic_table_args(
user_table = basic_table_args,
module_table = teal.widgets::basic_table_args(title = main_title)
module_table = teal.widgets::basic_table_args(
title = main_title,
subtitles = subtitle
)
)
teal.code::chunks_push(expression = quote(result <- list()), id = "result_initiation_call")
lapply(unlist(input$buckets$Comp), function(x) {
Expand Down
2 changes: 1 addition & 1 deletion man/template_coxreg_u.Rd

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

6 changes: 4 additions & 2 deletions tests/testthat/test-tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ testthat::test_that("template_forest_tte generates correct expressions", {
}),
plot = quote({
p <- decorate_grob(g_forest(tbl = result, col_symbol_size = NULL),
titles = "Forest plot of survival duration for ", footnotes = "",
gp_footnotes = grid::gpar(fontsize = 12)
titles = c(),
footnotes = "", gp_footnotes = grid::gpar(fontsize = 12)
)
grid::grid.newpage()
grid::grid.draw(p)
})
)
expected$plot[[2]][[3]]$titles <- c("Forest Plot of Survival Duration for ", "Stratified by STRATA2")

testthat::expect_equal(result, expected)
})
23 changes: 16 additions & 7 deletions tests/testthat/test-tm_t_binary_outcome.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ testthat::test_that("template_binary_outcome generates standard expressions", {
}),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = ""
) %>%
rtables::split_cols_by(var = "ARMCD", ref_group = "ARM A") %>%
rtables::add_colcounts() %>%
Expand Down Expand Up @@ -101,7 +102,10 @@ testthat::test_that("template_binary_outcome generates right expressions with no
df_explicit_na()
}),
layout = quote(
lyt <- rtables::basic_table(title = "Table of BESRSPI for PR and SD Responders") %>%
lyt <- rtables::basic_table(
title = "Table of BESRSPI for PR and SD Responders",
subtitles = ""
) %>%
rtables::split_cols_by(var = "ARM", ref_group = "B: Placebo") %>%
rtables::add_colcounts() %>%
estimate_proportion(
Expand Down Expand Up @@ -163,7 +167,8 @@ testthat::test_that("template_binary_outcome generates expression without arm co
}),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = ""
) %>%
rtables::split_cols_by(var = "ARM") %>%
rtables::add_colcounts() %>%
Expand Down Expand Up @@ -219,7 +224,8 @@ testthat::test_that("template_binary_outcome generates expression with non-defau
}),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = "Stratified by SEX"
) %>%
rtables::split_cols_by(var = "ARM", ref_group = "B: Placebo") %>%
rtables::add_colcounts() %>%
Expand Down Expand Up @@ -311,7 +317,8 @@ testthat::test_that("template_binary_outcome can combine comparison arms", {
),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = ""
) %>%
split_cols_by_groups(
var = "ARMCD", groups_list = groups, ref_group = names(groups)[1]
Expand Down Expand Up @@ -385,7 +392,8 @@ testthat::test_that("template_binary_outcome can combine comparison arms when co
}),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = ""
) %>%
rtables::split_cols_by(var = "ARMCD") %>%
rtables::add_colcounts() %>%
Expand Down Expand Up @@ -454,7 +462,8 @@ testthat::test_that("template_binary_outcome can combine refs", {
}),
layout = quote(
lyt <- rtables::basic_table(
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders"
title = "Table of BESRSPI for Complete Response (CR) and Partial Response (PR) Responders",
subtitles = ""
) %>%
rtables::split_cols_by(var = "ARMCD", ref_group = "ARM A/ARM B") %>%
rtables::add_colcounts() %>%
Expand Down

0 comments on commit 86f7f04

Please sign in to comment.