Skip to content

Commit

Permalink
Fix TMC to work with tern v0.9.3 (#922)
Browse files Browse the repository at this point in the history
Fixes #921
  • Loading branch information
edelarua authored Jan 18, 2024
1 parent da53aef commit 157c8cf
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 187 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: insightsengineering/r.pkg.template/.github/workflows/audit.yaml@main
r-cmd:
name: R CMD Check 🧬
uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main
uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@install-tern-from-cran
secrets:
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
with:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
uses: insightsengineering/r.pkg.template/.github/workflows/linter.yaml@main
roxygen:
name: Roxygen 🅾
uses: insightsengineering/r.pkg.template/.github/workflows/roxygen.yaml@main
uses: insightsengineering/r.pkg.template/.github/workflows/roxygen.yaml@install-tern-from-cran
secrets:
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ on:
jobs:
docs:
name: Pkgdown Docs 📚
uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@main
uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@install-tern-from-cran
secrets:
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
with:
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ Depends:
R (>= 4.0),
teal (>= 0.14.0.9027),
teal.transform (>= 0.4.0.9011),
tern (>= 0.9.3.9002)
tern (== 0.9.3)
Imports:
assertthat,
broom,
checkmate,
cowplot (>= 0.7.0),
dplyr,
DT,
formatters (>= 0.5.5),
Expand Down
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* Added parameter `sort_freq_col` to `tm_t_events` to allow the user to select column to use when sorting by decreasing frequency.
* Added parameter `incl_overall_sum` to `tm_t_events` to allow the user to choose whether overall summary rows are included at the top of the table.
* Updated the documentation and vignettes to demonstrate method to pass `teal_data` object to `teal::init()`.
* Updated `tm_g_forest_rsp` and `tm_g_forest_tte` to use refactored version of `g_forest`. Plots are now displayed as `ggplot` objects instead of `grob` objects. Added parameters `font_size` and `rel_width_forest` to control font size and width of plot relative to table, respectively.

### Bug fixes
* Fixed bug in `tm_g_lineplot` forcing module to initialize with a table.
Expand Down
87 changes: 22 additions & 65 deletions R/tm_g_forest_rsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#'
#' Creates a valid expression for response forest plot.
#'
#' @inheritParams tern::g_forest
#' @inheritParams template_arguments
#' @param obj_var_name (`character`)\cr additional text string append to output title.
#' @param responders (`character`)\cr values of `aval_var` that are considered to be responders.
Expand Down Expand Up @@ -35,8 +34,6 @@ template_forest_rsp <- function(dataname = "ANL",
strata_var = NULL,
conf_level = 0.95,
col_symbol_size = NULL,
rel_width_forest = 0.25,
font_size = 15,
ggplot2_args = teal.widgets::ggplot2_args()) {
assertthat::assert_that(
assertthat::is.string(dataname),
Expand All @@ -46,8 +43,6 @@ template_forest_rsp <- function(dataname = "ANL",
assertthat::is.string(obj_var_name),
is.null(subgroup_var) || is.character(subgroup_var)
)
checkmate::assert_number(rel_width_forest, lower = 0, upper = 1)
checkmate::assert_number(font_size)

y <- list()
ref_arm_val <- paste(ref_arm, collapse = "/")
Expand Down Expand Up @@ -165,55 +160,34 @@ template_forest_rsp <- function(dataname = "ANL",
all_ggplot2_args <- teal.widgets::resolve_ggplot2_args(
user_plot = ggplot2_args,
module_plot = teal.widgets::ggplot2_args(
labs = list(
title = paste("Forest Plot of Best Overall Response for", obj_var_name),
caption = ""
)
labs = list(title = paste0("Forest plot of best overall response for ", obj_var_name), caption = "")
)
)

plot_list <- list()
plot_call <- substitute(
expr = g_forest(
tbl = result,
col_symbol_size = col_s_size
),
env = list(col_s_size = col_symbol_size)
)

plot_list <- add_expr(
plot_list,
substitute(
expr = {
f <- g_forest(
tbl = result,
col_symbol_size = col_s_size,
font_size = font_size,
as_list = TRUE
)
},
env = list(
col_s_size = col_symbol_size,
font_size = font_size
)
)
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)
)

plot_list <- add_expr(
plot_list,
substitute(
expr = {
p <- cowplot::plot_grid(
f[["table"]] + ggplot2::labs(title = ggplot2_args_title),
f[["plot"]] + ggplot2::labs(caption = ggplot2_args_caption),
align = "h",
axis = "tblr",
rel_widths = c(1 - rel_width_forest, rel_width_forest)
)
},
env = list(
rel_width_forest = rel_width_forest,
ggplot2_args_title = all_ggplot2_args$labs$title,
ggplot2_args_caption = all_ggplot2_args$labs$caption
)
)
plot_call <- substitute(
expr = {
p <- plot_call
grid::grid.newpage()
grid::grid.draw(p)
},
env = list(plot_call = plot_call)
)

# Plot output.
y$plot <- plot_list
y$plot <- plot_call

y
}
Expand All @@ -222,7 +196,6 @@ template_forest_rsp <- function(dataname = "ANL",
#'
#' This teal module produces a grid style Forest plot for response data with `ADaM` structure.
#'
#' @inheritParams tern::g_forest
#' @inheritParams module_arguments
#' @inheritParams tm_t_binary_outcome
#' @param fixed_symbol_size (`logical`)\cr
Expand Down Expand Up @@ -341,10 +314,8 @@ tm_g_forest_rsp <- function(label,
fixed_symbol_size = TRUE,
conf_level = teal.transform::choices_selected(c(0.95, 0.9, 0.8), 0.95, keep_order = TRUE),
default_responses = c("CR", "PR", "Y", "Complete Response (CR)", "Partial Response (PR)"),
plot_height = c(500L, 200L, 2000L),
plot_width = c(1500L, 800L, 3000L),
rel_width_forest = c(25L, 0L, 100L),
font_size = c(15L, 1L, 30L),
plot_height = c(700L, 200L, 2000L),
plot_width = c(1200L, 800L, 3000L),
pre_output = NULL,
post_output = NULL,
ggplot2_args = teal.widgets::ggplot2_args()) {
Expand Down Expand Up @@ -471,19 +442,7 @@ ui_g_forest_rsp <- function(id, ...) {
multiple = FALSE,
fixed = a$conf_level$fixed
),
shiny::checkboxInput(ns("fixed_symbol_size"), "Fixed symbol size", value = TRUE),
teal.widgets::optionalSliderInputValMinMax(
ns("rel_width_forest"),
"Relative Width of Forest Plot (%)",
a$rel_width_forest,
ticks = FALSE, step = 1
),
teal.widgets::optionalSliderInputValMinMax(
ns("font_size"),
"Table Font Size",
a$font_size,
ticks = FALSE, step = 1
)
shiny::checkboxInput(ns("fixed_symbol_size"), "Fixed symbol size", value = TRUE)
)
)
),
Expand Down Expand Up @@ -733,8 +692,6 @@ srv_g_forest_rsp <- function(id,
strata_var = if (length(strata_var) != 0) strata_var else NULL,
conf_level = as.numeric(input$conf_level),
col_symbol_size = `if`(input$fixed_symbol_size, NULL, 1),
rel_width_forest = input$rel_width_forest / 100,
font_size = input$font_size,
ggplot2_args = ggplot2_args
)

Expand Down
96 changes: 31 additions & 65 deletions R/tm_g_forest_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ template_forest_tte <- function(dataname = "ANL",
conf_level = 0.95,
col_symbol_size = NULL,
time_unit_var = "AVALU",
rel_width_forest = 0.25,
font_size = 15,
ggplot2_args = teal.widgets::ggplot2_args()) {
assertthat::assert_that(
assertthat::is.string(dataname),
assertthat::is.string(arm_var),
assertthat::is.string(obj_var_name),
is.character(subgroup_var) || is.null(subgroup_var)
)
checkmate::assert_number(rel_width_forest, lower = 0, upper = 1)
checkmate::assert_number(font_size)

y <- list()
ref_arm_val <- paste(ref_arm, collapse = "/")
Expand Down Expand Up @@ -166,59 +162,45 @@ template_forest_tte <- function(dataname = "ANL",
user_plot = ggplot2_args,
module_plot = teal.widgets::ggplot2_args(
labs = list(
title = paste(
paste("Forest Plot of Survival Duration for", obj_var_name),
ifelse(is.null(strata_var), "", paste("Stratified by", paste(strata_var, collapse = " and "))),
sep = "\n"
),
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 = ""
)
)
)

plot_list <- list()
plot_call <- substitute(
expr = g_forest(
tbl = result,
col_symbol_size = col_s_size
),
env = list(col_s_size = col_symbol_size)
)

plot_list <- add_expr(
plot_list,
substitute(
expr = {
f <- g_forest(
tbl = result,
col_symbol_size = col_s_size,
font_size = font_size,
as_list = TRUE
)
},
env = list(
col_s_size = col_symbol_size,
font_size = font_size
)
plot_call <- substitute(
decorate_grob(p, titles = title, footnotes = caption, gp_footnotes = grid::gpar(fontsize = 12)),
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_list <- add_expr(
plot_list,
substitute(
expr = {
p <- cowplot::plot_grid(
f[["table"]] + ggplot2::labs(title = ggplot2_args_title, subtitle = ggplot2_args_subtitle),
f[["plot"]] + ggplot2::labs(caption = ggplot2_args_caption),
align = "h",
axis = "tblr",
rel_widths = c(1 - rel_width_forest, rel_width_forest)
)
},
env = list(
rel_width_forest = rel_width_forest,
ggplot2_args_title = all_ggplot2_args$labs$title,
ggplot2_args_subtitle = all_ggplot2_args$labs$subtitle,
ggplot2_args_caption = all_ggplot2_args$labs$caption
)
)
plot_call <- substitute(
env = list(plot_call = plot_call),
expr = {
p <- plot_call
grid::grid.newpage()
grid::grid.draw(p)
}
)

# Plot output.
y$plot <- plot_list
y$plot <- plot_call

y
}
Expand All @@ -228,7 +210,6 @@ template_forest_tte <- function(dataname = "ANL",
#' This teal module produces a grid style Forest plot for time-to-event data
#' with `ADaM` structure
#'
#' @inheritParams tern::g_forest
#' @inheritParams module_arguments
#' @inheritParams tm_g_forest_rsp
#' @param ggplot2_args optional, (`ggplot2_args`)\cr
Expand Down Expand Up @@ -290,7 +271,8 @@ template_forest_tte <- function(dataname = "ANL",
#' strata_var = choices_selected(
#' variable_choices(ADSL, c("STRATA1", "STRATA2")),
#' "STRATA2"
#' )
#' ),
#' plot_height = c(600, 200, 2000)
#' )
#' )
#' )
Expand Down Expand Up @@ -324,10 +306,8 @@ tm_g_forest_tte <- function(label,
fixed = TRUE
),
fixed_symbol_size = TRUE,
plot_height = c(500L, 200L, 2000L),
plot_width = c(1500L, 800L, 3000L),
rel_width_forest = c(25L, 0L, 100L),
font_size = c(15L, 1L, 30L),
plot_height = c(700L, 200L, 2000L),
plot_width = c(1200L, 800L, 3000L),
pre_output = NULL,
post_output = NULL,
ggplot2_args = teal.widgets::ggplot2_args()) {
Expand Down Expand Up @@ -463,18 +443,6 @@ ui_g_forest_tte <- function(id, ...) {
label = "Time Unit Variable",
data_extract_spec = a$time_unit_var,
is_single_dataset = is_single_dataset_value
),
teal.widgets::optionalSliderInputValMinMax(
ns("rel_width_forest"),
"Relative Width of Forest Plot (%)",
a$rel_width_forest,
ticks = FALSE, step = 1
),
teal.widgets::optionalSliderInputValMinMax(
ns("font_size"),
"Table Font Size",
a$font_size,
ticks = FALSE, step = 1
)
)
)
Expand Down Expand Up @@ -656,8 +624,6 @@ srv_g_forest_tte <- function(id,
conf_level = as.numeric(input$conf_level),
col_symbol_size = if (!input$fixed_symbol_size) 1,
time_unit_var = as.vector(anl_m$columns_source$time_unit_var),
rel_width_forest = input$rel_width_forest / 100,
font_size = input$font_size,
ggplot2_args = ggplot2_args
)
teal.code::eval_code(anl_q(), as.expression(my_calls))
Expand Down
7 changes: 0 additions & 7 deletions man/template_forest_rsp.Rd

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

Loading

0 comments on commit 157c8cf

Please sign in to comment.