From 44b47c1ee07f4da82ae2a82c01a269daf6cd3ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Tue, 3 Dec 2024 15:41:44 +0100 Subject: [PATCH 01/10] Introduce decorators for `tm_t_events_by_grade` --- R/tm_t_events_by_grade.R | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index f0b01a543..fda747195 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -7,9 +7,18 @@ #' @param grade (`character`)\cr name of the severity level variable. #' @param label_grade (`string`)\cr label of the `grade` variable from `dataname`. The label will be extracted from the #' module. +#' @param decorators `r roxygen_decorators_param("tm_t_events_by_grade")` #' #' @inherit template_arguments return #' +#' @section Decorating `tm_t_events_by_grade`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `table` (`TableTree` as created from `rtables::build_table`) +#' +#' For additional details and examples of decorators, refer to the vignette +#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation. +#' #' @seealso [tm_t_events_by_grade()] #' #' @keywords internal @@ -303,7 +312,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = pruned_result <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) + expr = table <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) ) ) } @@ -345,7 +354,7 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - pruned_and_sorted_result <- pruned_result %>% + table <- pruned_result %>% sort_at_path(path = hlt, scorefun = scorefun, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun, decreasing = TRUE) }, @@ -359,7 +368,7 @@ template_events_by_grade <- function(dataname, sort_list <- add_expr( sort_list, - quote(pruned_and_sorted_result) + quote(table) ) } y$sort <- bracket_expr(sort_list) @@ -865,7 +874,8 @@ tm_t_events_by_grade <- function(label, drop_arm_levels = TRUE, pre_output = NULL, post_output = NULL, - basic_table_args = teal.widgets::basic_table_args()) { + basic_table_args = teal.widgets::basic_table_args(), + decorators = NULL) { message("Initializing tm_t_events_by_grade") checkmate::assert_string(label) checkmate::assert_string(dataname) @@ -883,6 +893,8 @@ tm_t_events_by_grade <- function(label, checkmate::assert_class(pre_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(post_output, classes = "shiny.tag", null.ok = TRUE) checkmate::assert_class(basic_table_args, "basic_table_args") + decorators <- normalize_decorators(decorators) + assert_decorators(decorators, "table", null.ok = TRUE) args <- as.list(environment()) @@ -907,7 +919,8 @@ tm_t_events_by_grade <- function(label, total_label = total_label, grading_groups = grading_groups, na_level = na_level, - basic_table_args = basic_table_args + basic_table_args = basic_table_args, + decorators = decorators ) ), datanames = teal.transform::get_extract_datanames(data_extract_list) @@ -962,6 +975,7 @@ ui_t_events_by_grade <- function(id, ...) { "Display grade groupings in nested columns", value = a$col_by_grade ), + ui_decorate_teal_data(ns("decorator"), decorators = select_decorators(a$decorators, "table")), teal.widgets::panel_group( teal.widgets::panel_item( "Additional table settings", @@ -1017,7 +1031,8 @@ srv_t_events_by_grade <- function(id, drop_arm_levels, total_label, na_level, - basic_table_args) { + basic_table_args, + decorators) { with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") @@ -1202,9 +1217,17 @@ srv_t_events_by_grade <- function(id, teal.code::eval_code(merged$anl_q(), as.expression(unlist(my_calls))) }) + + decorated_table_q <- srv_decorate_teal_data( + id = "decorator", + data = table_q, + decorators = select_decorators(decorators, "table"), + expr = table + ) # Outputs to render. table_r <- reactive({ - table_q()[["pruned_and_sorted_result"]] + browser() + decorated_table_q()[["table"]] }) teal.widgets::table_with_settings_srv( @@ -1215,7 +1238,7 @@ srv_t_events_by_grade <- function(id, # Render R code. teal.widgets::verbatim_popup_srv( id = "rcode", - verbatim_content = reactive(teal.code::get_code(table_q())), + verbatim_content = reactive(teal.code::get_code(req(decorated_table_q()))), title = label ) @@ -1234,7 +1257,7 @@ srv_t_events_by_grade <- function(id, card$append_text("Comment", "header3") card$append_text(comment) } - card$append_src(teal.code::get_code(table_q())) + card$append_src(teal.code::get_code(req(decorated_table_q()))) card } teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun) From ef1dd5dea80c2d37e7763668b330ddbcedc23621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Tue, 3 Dec 2024 15:48:39 +0100 Subject: [PATCH 02/10] Remove browse --- R/tm_t_events_by_grade.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index fda747195..f1230f95e 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -1226,7 +1226,6 @@ srv_t_events_by_grade <- function(id, ) # Outputs to render. table_r <- reactive({ - browser() decorated_table_q()[["table"]] }) From bceadbb636bda545e8f5bc8844382eaae99987df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Wed, 4 Dec 2024 10:17:07 +0100 Subject: [PATCH 03/10] Rename results by table specially `template_events_col_by_grade` --- R/tm_t_events_by_grade.R | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index f1230f95e..e487340b5 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -258,7 +258,7 @@ template_events_by_grade <- function(dataname, # Full table. y$table <- substitute( - expr = result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent), + expr = table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent), env = list(parent = as.name(parentname)) ) @@ -267,7 +267,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, quote( - pruned_result <- result + pruned_table <- table ) ) @@ -276,7 +276,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = col_indices <- 1:(ncol(result) - add_total), + expr = col_indices <- 1:(ncol(table) - add_total), env = list(add_total = add_total) ) ) @@ -312,7 +312,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = table <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) + expr = table <- pruned_table %>% rtables::prune_table(keep_content_rows(row_condition)) ) ) } @@ -339,9 +339,9 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - pruned_and_sorted_result <- pruned_result %>% + pruned_and_sorted_table <- pruned_table %>% sort_at_path(path = term_var, scorefun = scorefun, decreasing = TRUE) - pruned_and_sorted_result + pruned_and_sorted_table }, env = list( term_var = term_var, @@ -354,7 +354,7 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - table <- pruned_result %>% + table <- pruned_table %>% sort_at_path(path = hlt, scorefun = scorefun, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun, decreasing = TRUE) }, @@ -647,7 +647,7 @@ template_events_col_by_grade <- function(dataname, ) # Full table. - y$table <- quote(result <- rtables::build_table(lyt = lyt, df = anl, col_counts = col_counts)) + y$table <- quote(table <- rtables::build_table(lyt = lyt, df = anl, col_counts = col_counts)) # Start sorting table. sort_list <- list() @@ -666,7 +666,7 @@ template_events_col_by_grade <- function(dataname, sort_list <- add_expr( sort_list, substitute( - expr = col_indices <- seq(start_index, ncol(result), by = length(grading_groups)), + expr = col_indices <- seq(start_index, ncol(table), by = length(grading_groups)), env = list(grading_groups = grading_groups) ) ) @@ -688,7 +688,7 @@ template_events_col_by_grade <- function(dataname, sort_list, substitute( expr = { - sorted_result <- result %>% + sorted_table <- table %>% sort_at_path(path = c(llt), scorefun = scorefun_term, decreasing = TRUE) }, env = list(llt = llt) @@ -699,7 +699,7 @@ template_events_col_by_grade <- function(dataname, sort_list, substitute( expr = { - sorted_result <- result %>% + sorted_table <- table %>% sort_at_path(path = c(hlt), scorefun = scorefun_soc, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun_term, decreasing = TRUE) }, @@ -748,7 +748,7 @@ template_events_col_by_grade <- function(dataname, prune_pipe <- add_expr( prune_pipe, quote( - pruned_and_sorted_result <- sorted_result %>% rtables::trim_rows(criteria = criteria_fun) + pruned_and_sorted_table <- sorted_table %>% rtables::trim_rows(criteria = criteria_fun) ) ) @@ -780,7 +780,7 @@ template_events_col_by_grade <- function(dataname, ) prune_list <- add_expr( prune_list, - quote(pruned_and_sorted_result) + quote(pruned_and_sorted_table) ) y$prune <- bracket_expr(prune_list) From f68f68bcec8d142553ca760254564c8d8c115657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Wed, 4 Dec 2024 12:01:18 +0100 Subject: [PATCH 04/10] Document module --- man/template_events_by_grade.Rd | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/man/template_events_by_grade.Rd b/man/template_events_by_grade.Rd index bb7b8a8bc..80bdf8ac3 100644 --- a/man/template_events_by_grade.Rd +++ b/man/template_events_by_grade.Rd @@ -72,6 +72,12 @@ user input for this parameter is ignored.} with settings for the module table. The argument is merged with option \code{teal.basic_table_args} and with default module arguments (hard coded in the module body). For more details, see the vignette: \code{vignette("custom-basic-table-arguments", package = "teal.widgets")}.} + +\item{decorators}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} (\code{list} of \code{teal_transform_module}, named \code{list} of \code{teal_transform_module} or \code{NULL}) optional, if not \code{NULL}, decorator for tables or plots included in the module. When a named list of \code{teal_transform_module}, the decorators are applied to the respective output objects. + +Otherwise, the decorators are applied to all objects, which is equivalent as using the name \code{default}. + +See section "Decorating \code{tm_t_events_by_grade}" below for more details.} } \value{ a \code{list} of expressions to generate a table or plot object. @@ -79,6 +85,18 @@ a \code{list} of expressions to generate a table or plot object. \description{ Creates a valid expression to generate a table to summarize events by grade. } +\section{Decorating \code{tm_t_events_by_grade}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{table} (\code{TableTree} as created from \code{rtables::build_table}) +} + +For additional details and examples of decorators, refer to the vignette +\code{vignette("decorate-modules-output", package = "teal")} or the \code{\link[=teal_transform_module]{teal_transform_module()}} documentation. +} + \seealso{ \code{\link[=tm_t_events_by_grade]{tm_t_events_by_grade()}} } From fd3f7ac7da30a692644467ff03ef95cf000a69eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Wed, 4 Dec 2024 12:34:53 +0100 Subject: [PATCH 05/10] Fix documentation issues --- R/tm_t_events_by_grade.R | 18 +++++++++--------- man/template_events_by_grade.Rd | 18 ------------------ man/tm_t_events_by_grade.Rd | 21 ++++++++++++++++++++- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index e487340b5..fcce86dd0 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -7,18 +7,9 @@ #' @param grade (`character`)\cr name of the severity level variable. #' @param label_grade (`string`)\cr label of the `grade` variable from `dataname`. The label will be extracted from the #' module. -#' @param decorators `r roxygen_decorators_param("tm_t_events_by_grade")` #' #' @inherit template_arguments return #' -#' @section Decorating `tm_t_events_by_grade`: -#' -#' This module generates the following objects, which can be modified in place using decorators: -#' - `table` (`TableTree` as created from `rtables::build_table`) -#' -#' For additional details and examples of decorators, refer to the vignette -#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation. -#' #' @seealso [tm_t_events_by_grade()] #' #' @keywords internal @@ -797,9 +788,18 @@ template_events_col_by_grade <- function(dataname, #' @inheritParams template_events_col_by_grade #' @param col_by_grade (`logical`)\cr whether to display the grading groups in nested columns. #' @param grading_groups (`list`)\cr named list of grading groups used when `col_by_grade = TRUE`. +#' @param decorators `r roxygen_decorators_param("tm_t_events_by_grade")` #' #' @inherit module_arguments return seealso #' +#' @section Decorating `tm_t_events_by_grade`: +#' +#' This module generates the following objects, which can be modified in place using decorators: +#' - `table` (`TableTree` as created from `rtables::build_table`) +#' +#' For additional details and examples of decorators, refer to the vignette +#' `vignette("decorate-modules-output", package = "teal")` or the [`teal_transform_module()`] documentation. +#' #' @export #' #' @examplesShinylive diff --git a/man/template_events_by_grade.Rd b/man/template_events_by_grade.Rd index 80bdf8ac3..bb7b8a8bc 100644 --- a/man/template_events_by_grade.Rd +++ b/man/template_events_by_grade.Rd @@ -72,12 +72,6 @@ user input for this parameter is ignored.} with settings for the module table. The argument is merged with option \code{teal.basic_table_args} and with default module arguments (hard coded in the module body). For more details, see the vignette: \code{vignette("custom-basic-table-arguments", package = "teal.widgets")}.} - -\item{decorators}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} (\code{list} of \code{teal_transform_module}, named \code{list} of \code{teal_transform_module} or \code{NULL}) optional, if not \code{NULL}, decorator for tables or plots included in the module. When a named list of \code{teal_transform_module}, the decorators are applied to the respective output objects. - -Otherwise, the decorators are applied to all objects, which is equivalent as using the name \code{default}. - -See section "Decorating \code{tm_t_events_by_grade}" below for more details.} } \value{ a \code{list} of expressions to generate a table or plot object. @@ -85,18 +79,6 @@ a \code{list} of expressions to generate a table or plot object. \description{ Creates a valid expression to generate a table to summarize events by grade. } -\section{Decorating \code{tm_t_events_by_grade}}{ - - -This module generates the following objects, which can be modified in place using decorators: -\itemize{ -\item \code{table} (\code{TableTree} as created from \code{rtables::build_table}) -} - -For additional details and examples of decorators, refer to the vignette -\code{vignette("decorate-modules-output", package = "teal")} or the \code{\link[=teal_transform_module]{teal_transform_module()}} documentation. -} - \seealso{ \code{\link[=tm_t_events_by_grade]{tm_t_events_by_grade()}} } diff --git a/man/tm_t_events_by_grade.Rd b/man/tm_t_events_by_grade.Rd index 158dcdced..e2ff4a1bd 100644 --- a/man/tm_t_events_by_grade.Rd +++ b/man/tm_t_events_by_grade.Rd @@ -24,7 +24,8 @@ tm_t_events_by_grade( drop_arm_levels = TRUE, pre_output = NULL, post_output = NULL, - basic_table_args = teal.widgets::basic_table_args() + basic_table_args = teal.widgets::basic_table_args(), + decorators = NULL ) } \arguments{ @@ -80,6 +81,12 @@ For example the \code{\link[shiny:helpText]{shiny::helpText()}} elements are use with settings for the module table. The argument is merged with option \code{teal.basic_table_args} and with default module arguments (hard coded in the module body). For more details, see the vignette: \code{vignette("custom-basic-table-arguments", package = "teal.widgets")}.} + +\item{decorators}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} (\code{list} of \code{teal_transform_module}, named \code{list} of \code{teal_transform_module} or \code{NULL}) optional, if not \code{NULL}, decorator for tables or plots included in the module. When a named list of \code{teal_transform_module}, the decorators are applied to the respective output objects. + +Otherwise, the decorators are applied to all objects, which is equivalent as using the name \code{default}. + +See section "Decorating \code{tm_t_events_by_grade}" below for more details.} } \value{ a \code{teal_module} object. @@ -87,6 +94,18 @@ a \code{teal_module} object. \description{ This module produces a table to summarize events by grade. } +\section{Decorating \code{tm_t_events_by_grade}}{ + + +This module generates the following objects, which can be modified in place using decorators: +\itemize{ +\item \code{table} (\code{TableTree} as created from \code{rtables::build_table}) +} + +For additional details and examples of decorators, refer to the vignette +\code{vignette("decorate-modules-output", package = "teal")} or the \code{\link[=teal_transform_module]{teal_transform_module()}} documentation. +} + \examples{ library(dplyr) data <- teal_data() From 0f9ff50df533953b0ad1fd91615df0d4551ef40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 5 Dec 2024 12:16:24 +0100 Subject: [PATCH 06/10] Revert table to result and add a reactive rename at the end the final object to table --- R/tm_t_events_by_grade.R | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index fcce86dd0..357ba81be 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -249,7 +249,7 @@ template_events_by_grade <- function(dataname, # Full table. y$table <- substitute( - expr = table <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent), + expr = result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = parent), env = list(parent = as.name(parentname)) ) @@ -258,7 +258,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, quote( - pruned_table <- table + pruned_result <- result ) ) @@ -267,7 +267,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = col_indices <- 1:(ncol(table) - add_total), + expr = col_indices <- 1:(ncol(result) - add_total), env = list(add_total = add_total) ) ) @@ -303,7 +303,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = table <- pruned_table %>% rtables::prune_table(keep_content_rows(row_condition)) + expr = result <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) ) ) } @@ -330,9 +330,9 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - pruned_and_sorted_table <- pruned_table %>% + pruned_and_sorted_result <- pruned_result %>% sort_at_path(path = term_var, scorefun = scorefun, decreasing = TRUE) - pruned_and_sorted_table + pruned_and_sorted_result }, env = list( term_var = term_var, @@ -345,7 +345,7 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - table <- pruned_table %>% + result <- pruned_result %>% sort_at_path(path = hlt, scorefun = scorefun, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun, decreasing = TRUE) }, @@ -359,7 +359,7 @@ template_events_by_grade <- function(dataname, sort_list <- add_expr( sort_list, - quote(table) + quote(result) ) } y$sort <- bracket_expr(sort_list) @@ -539,7 +539,7 @@ template_events_col_by_grade <- function(dataname, layout_list <- add_expr( layout_list, substitute( - expr = rtables::split_cols_by(var = arm_var, split_fun = add_overall_level(total_label, first = FALSE)), + expr = result <- rtables::split_cols_by(var = arm_var, split_fun = add_overall_level(total_label, first = FALSE)), env = list( arm_var = arm_var, total_label = total_label @@ -638,7 +638,7 @@ template_events_col_by_grade <- function(dataname, ) # Full table. - y$table <- quote(table <- rtables::build_table(lyt = lyt, df = anl, col_counts = col_counts)) + y$table <- quote(result <- rtables::build_table(lyt = lyt, df = anl, col_counts = col_counts)) # Start sorting table. sort_list <- list() @@ -657,7 +657,7 @@ template_events_col_by_grade <- function(dataname, sort_list <- add_expr( sort_list, substitute( - expr = col_indices <- seq(start_index, ncol(table), by = length(grading_groups)), + expr = col_indices <- seq(start_index, ncol(result), by = length(grading_groups)), env = list(grading_groups = grading_groups) ) ) @@ -679,7 +679,7 @@ template_events_col_by_grade <- function(dataname, sort_list, substitute( expr = { - sorted_table <- table %>% + sorted_result <- result %>% sort_at_path(path = c(llt), scorefun = scorefun_term, decreasing = TRUE) }, env = list(llt = llt) @@ -690,7 +690,7 @@ template_events_col_by_grade <- function(dataname, sort_list, substitute( expr = { - sorted_table <- table %>% + sorted_result <- result %>% sort_at_path(path = c(hlt), scorefun = scorefun_soc, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun_term, decreasing = TRUE) }, @@ -1218,9 +1218,19 @@ srv_t_events_by_grade <- function(id, }) + table_renamed_q <- reactive({ + req(table_q()) + if (length(table_q()[["prunned_and_sorted_result"]])) { + out <- within(table_q(), {table <- pruned_and_sorted_result}) + } else { + out <- within(table_q(), {table <- pruned_result}) + } + out + }) + decorated_table_q <- srv_decorate_teal_data( id = "decorator", - data = table_q, + data = table_renamed_q, decorators = select_decorators(decorators, "table"), expr = table ) From df9e050cab2ade048ea90e081d6f95c002c98f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 5 Dec 2024 12:27:02 +0100 Subject: [PATCH 07/10] I had erroneously changed this --- R/tm_t_events_by_grade.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 357ba81be..7fb0772f2 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -345,7 +345,7 @@ template_events_by_grade <- function(dataname, sort_list, substitute( expr = { - result <- pruned_result %>% + pruned_and_sorted_result <- pruned_result %>% sort_at_path(path = hlt, scorefun = scorefun, decreasing = TRUE) %>% sort_at_path(path = c(hlt, "*", llt), scorefun = scorefun, decreasing = TRUE) }, From d5324c868633294ab668bb6e545b3b14cfa725f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Thu, 5 Dec 2024 14:43:28 +0100 Subject: [PATCH 08/10] Avoid printing the tables twice --- R/tm_t_events_by_grade.R | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 7fb0772f2..02fc9ff86 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -303,7 +303,7 @@ template_events_by_grade <- function(dataname, prune_list <- add_expr( prune_list, substitute( - expr = result <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) + expr = pruned_result <- pruned_result %>% rtables::prune_table(keep_content_rows(row_condition)) ) ) } @@ -332,7 +332,6 @@ template_events_by_grade <- function(dataname, expr = { pruned_and_sorted_result <- pruned_result %>% sort_at_path(path = term_var, scorefun = scorefun, decreasing = TRUE) - pruned_and_sorted_result }, env = list( term_var = term_var, @@ -356,11 +355,6 @@ template_events_by_grade <- function(dataname, ) ) ) - - sort_list <- add_expr( - sort_list, - quote(result) - ) } y$sort <- bracket_expr(sort_list) @@ -539,7 +533,7 @@ template_events_col_by_grade <- function(dataname, layout_list <- add_expr( layout_list, substitute( - expr = result <- rtables::split_cols_by(var = arm_var, split_fun = add_overall_level(total_label, first = FALSE)), + expr = rtables::split_cols_by(var = arm_var, split_fun = add_overall_level(total_label, first = FALSE)), env = list( arm_var = arm_var, total_label = total_label @@ -739,7 +733,7 @@ template_events_col_by_grade <- function(dataname, prune_pipe <- add_expr( prune_pipe, quote( - pruned_and_sorted_table <- sorted_table %>% rtables::trim_rows(criteria = criteria_fun) + pruned_and_sorted_result <- sorted_result %>% rtables::trim_rows(criteria = criteria_fun) ) ) @@ -769,11 +763,6 @@ template_events_col_by_grade <- function(dataname, prune_list, prune_pipe ) - prune_list <- add_expr( - prune_list, - quote(pruned_and_sorted_table) - ) - y$prune <- bracket_expr(prune_list) y @@ -1219,8 +1208,7 @@ srv_t_events_by_grade <- function(id, table_renamed_q <- reactive({ - req(table_q()) - if (length(table_q()[["prunned_and_sorted_result"]])) { + if (length(table_q()[["pruned_and_sorted_result"]])) { out <- within(table_q(), {table <- pruned_and_sorted_result}) } else { out <- within(table_q(), {table <- pruned_result}) From 2afa1e9dac352cd88b95538b798d07ef32346f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= <185338939+llrs-roche@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:40:59 +0100 Subject: [PATCH 09/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Signed-off-by: Lluís Revilla <185338939+llrs-roche@users.noreply.github.com> --- R/tm_t_events_by_grade.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 02fc9ff86..5ea465397 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -777,11 +777,10 @@ template_events_col_by_grade <- function(dataname, #' @inheritParams template_events_col_by_grade #' @param col_by_grade (`logical`)\cr whether to display the grading groups in nested columns. #' @param grading_groups (`list`)\cr named list of grading groups used when `col_by_grade = TRUE`. -#' @param decorators `r roxygen_decorators_param("tm_t_events_by_grade")` #' #' @inherit module_arguments return seealso #' -#' @section Decorating `tm_t_events_by_grade`: +#' @section Decorating Module: #' #' This module generates the following objects, which can be modified in place using decorators: #' - `table` (`TableTree` as created from `rtables::build_table`) From e3435a3eca3f7f7198fbdc75a0bd78082da183a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Revilla?= Date: Wed, 11 Dec 2024 09:45:21 +0100 Subject: [PATCH 10/10] Simplify renaming --- R/tm_t_events_by_grade.R | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/R/tm_t_events_by_grade.R b/R/tm_t_events_by_grade.R index 02fc9ff86..91fcaacd0 100644 --- a/R/tm_t_events_by_grade.R +++ b/R/tm_t_events_by_grade.R @@ -1208,12 +1208,7 @@ srv_t_events_by_grade <- function(id, table_renamed_q <- reactive({ - if (length(table_q()[["pruned_and_sorted_result"]])) { - out <- within(table_q(), {table <- pruned_and_sorted_result}) - } else { - out <- within(table_q(), {table <- pruned_result}) - } - out + within(table_q(), {table <- pruned_and_sorted_result}) }) decorated_table_q <- srv_decorate_teal_data(