From 0bc68804a49116a8c69c8ece8bf36b51a1c88b51 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:15:28 -0500 Subject: [PATCH 01/13] Update summarize_glm_count --- R/summarize_glm_count.R | 108 ++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 25 deletions(-) diff --git a/R/summarize_glm_count.R b/R/summarize_glm_count.R index 82fb8023f4..71e408d633 100644 --- a/R/summarize_glm_count.R +++ b/R/summarize_glm_count.R @@ -118,6 +118,7 @@ summarize_glm_count <- function(lyt, show_labels = "visible", table_names = vars, .stats = get_stats("summarize_glm_count"), + .stat_names = NULL, .formats = NULL, .labels = NULL, .indent_mods = c( @@ -130,35 +131,35 @@ summarize_glm_count <- function(lyt, )) { checkmate::assert_choice(rate_mean_method, c("emmeans", "ppmeans")) - extra_args <- list( - variables = variables, distribution = distribution, conf_level = conf_level, - rate_mean_method = rate_mean_method, weights = weights, scale = scale, ... + # Process standard extra arguments + extra_args <- list(".stats" = .stats) + if (!is.null(.stat_names)) extra_args[[".stat_names"]] <- .stat_names + if (!is.null(.formats)) extra_args[[".formats"]] <- .formats + if (!is.null(.labels)) extra_args[[".labels"]] <- .labels + if (!is.null(.indent_mods)) extra_args[[".indent_mods"]] <- .indent_mods + + # Process additional arguments to the statistic function + extra_args <- c( + extra_args, + variables = list(variables), distribution = list(distribution), conf_level = list(conf_level), + rate_mean_method = list(rate_mean_method), weights = list(weights), scale = list(scale), + ... ) - # Selecting parameters following the statistics - .formats <- get_formats_from_stats(.stats, formats_in = .formats) - .labels <- get_labels_from_stats(.stats, labels_in = .labels) - .indent_mods <- get_indents_from_stats(.stats, indents_in = .indent_mods) - - afun <- make_afun( - s_glm_count, - .stats = .stats, - .formats = .formats, - .labels = .labels, - .indent_mods = .indent_mods, - .null_ref_cells = FALSE - ) + # Append additional info from layout to the analysis function + extra_args[[".additional_fun_parameters"]] <- get_additional_afun_params(add_alt_df = FALSE) + formals(a_glm_count) <- c(formals(a_glm_count), extra_args[[".additional_fun_parameters"]]) analyze( - lyt, - vars, - var_labels = var_labels, - show_labels = show_labels, - table_names = table_names, - afun = afun, + lyt = lyt, + vars = vars, + afun = a_glm_count, na_str = na_str, nested = nested, - extra_args = extra_args + extra_args = extra_args, + var_labels = var_labels, + show_labels = show_labels, + table_names = table_names ) } @@ -178,14 +179,15 @@ summarize_glm_count <- function(lyt, s_glm_count <- function(df, .var, .df_row, - variables, .ref_group, .in_ref_col, + variables, distribution, conf_level, rate_mean_method, weights, - scale = 1) { + scale = 1, + ...) { arm <- variables$arm y <- df[[.var]] @@ -272,7 +274,63 @@ s_glm_count <- function(df, ) } } + +#' @describeIn summarize_glm_count Formatted analysis function which is used as `afun` in `summarize_glm_count()`. +#' +#' @return +#' * `a_glm_count()` returns the corresponding list with formatted [rtables::CellValue()]. +#' +#' @keywords internal +a_glm_count <- function(df, + ..., + .stats = NULL, + .stat_names = NULL, + .formats = NULL, + .labels = NULL, + .indent_mods = NULL) { + # Check for additional parameters to the statistics function + dots_extra_args <- list(...) + extra_afun_params <- retrieve_extra_afun_params(names(dots_extra_args$.additional_fun_parameters)) + dots_extra_args$.additional_fun_parameters <- NULL + + # Apply statistics function + x_stats <- .apply_stat_functions( + default_stat_fnc = s_glm_count, + custom_stat_fnc_list = NULL, + args_list = c( + df = list(df), + extra_afun_params, + dots_extra_args + ) + ) + + # Fill in formatting defaults + .stats <- get_stats("summarize_glm_count", stats_in = .stats) + levels_per_stats <- as.list(.stats) %>% setNames(.stats) + .formats <- get_formats_from_stats(.stats, .formats, levels_per_stats) + .labels <- get_labels_from_stats(.stats, .labels, levels_per_stats) + .indent_mods <- get_indents_from_stats(.stats, .indent_mods, levels_per_stats) + + x_stats <- x_stats[.stats] + + # Auto format handling + .formats <- apply_auto_formatting(.formats, x_stats, extra_afun_params$.df_row, extra_afun_params$.var) + + # Get and check statistical names + .stat_names <- get_stat_names(x_stats, .stat_names) + + in_rows( + .list = x_stats, + .formats = .formats, + .names = .labels %>% .unlist_keep_nulls(), + .stat_names = .stat_names, + .labels = .labels %>% .unlist_keep_nulls(), + .indent_mods = .indent_mods %>% .unlist_keep_nulls() + ) +} + # h_glm_count ------------------------------------------------------------------ + #' Helper functions for Poisson models #' #' @description `r lifecycle::badge("experimental")` From 5cf1aad2e866a75977c65d6b4a8ccb58364533dc Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:15:35 -0500 Subject: [PATCH 02/13] Update NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 7a40545c5b..d3d74ebf30 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,7 @@ # tern 0.9.7.9004 ### Enhancements -* Refactored `count_abnormal()`, `count_abnormal_by_baseline()`, `count_abnormal_by_marked()`, `count_abnormal_by_worst_grade()`, and `count_abnormal_lab_worsen_by_baseline()` to work without `make_afun()`. +* Refactored `count_abnormal()`, `count_abnormal_by_baseline()`, `count_abnormal_by_marked()`, `count_abnormal_by_worst_grade()`, `count_abnormal_lab_worsen_by_baseline()`, `summarize_ancova()`, and `summarize_glm_count()` to work without `make_afun()`. ### Bug Fixes * Fixed bug in `a_count_patients_with_flags()` preventing select custom label and indentation specification formats from being applied. From 5c27ade558d09614ffad3a8dc3843657376694ac Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:26:10 -0500 Subject: [PATCH 03/13] Defaults --- R/summarize_glm_count.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/summarize_glm_count.R b/R/summarize_glm_count.R index 71e408d633..e34bb347c1 100644 --- a/R/summarize_glm_count.R +++ b/R/summarize_glm_count.R @@ -121,7 +121,7 @@ summarize_glm_count <- function(lyt, .stat_names = NULL, .formats = NULL, .labels = NULL, - .indent_mods = c( + .indent_mods = list( "n" = 0L, "rate" = 0L, "rate_ci" = 1L, From f17c25fd5cb98a19f825046f42334dd23fb602f5 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:36:15 -0500 Subject: [PATCH 04/13] Update summarize_ancova --- R/summarize_ancova.R | 127 +++++++++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 35 deletions(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index c3df762be9..c685df234f 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -111,12 +111,13 @@ h_ancova <- function(.var, s_ancova <- function(df, .var, .df_row, - variables, .ref_group, .in_ref_col, + variables, conf_level, interaction_y = FALSE, - interaction_item = NULL) { + interaction_item = NULL, + ...) { emmeans_fit <- h_ancova(.var = .var, variables = variables, .df_row = .df_row, interaction_item = interaction_item) sum_fit <- summary( @@ -207,18 +208,57 @@ s_ancova <- function(df, #' * `a_ancova()` returns the corresponding list with formatted [rtables::CellValue()]. #' #' @keywords internal -a_ancova <- make_afun( - s_ancova, - .indent_mods = c("n" = 0L, "lsmean" = 0L, "lsmean_diff" = 0L, "lsmean_diff_ci" = 1L, "pval" = 1L), - .formats = c( - "n" = "xx", - "lsmean" = "xx.xx", - "lsmean_diff" = "xx.xx", - "lsmean_diff_ci" = "(xx.xx, xx.xx)", - "pval" = "x.xxxx | (<0.0001)" - ), - .null_ref_cells = FALSE -) +a_ancova <- function(df, + ..., + .stats = NULL, + .stat_names = NULL, + .formats = NULL, + .labels = NULL, + .indent_mods = NULL) { + # Check for additional parameters to the statistics function + dots_extra_args <- list(...) + extra_afun_params <- retrieve_extra_afun_params(names(dots_extra_args$.additional_fun_parameters)) + dots_extra_args$.additional_fun_parameters <- NULL + + # browser() + # Apply statistics function + x_stats <- .apply_stat_functions( + default_stat_fnc = s_ancova, + custom_stat_fnc_list = NULL, + args_list = c( + df = list(df), + extra_afun_params, + dots_extra_args + ) + ) + + # Fill in formatting defaults + .stats <- get_stats("summarize_ancova", stats_in = .stats) + levels_per_stats <- as.list(.stats) %>% setNames(.stats) + x_stats <- x_stats[.stats] + .formats <- get_formats_from_stats(.stats, .formats, levels_per_stats) + .labels <- get_labels_from_stats( + .stats, .labels, levels_per_stats, + tern_defaults = c(lapply(x_stats[names(x_stats) != "n"], attr, "label"), tern_default_labels) + ) + .indent_mods <- get_indents_from_stats(.stats, .indent_mods, levels_per_stats) + + + # Auto format handling + .formats <- apply_auto_formatting(.formats, x_stats, extra_afun_params$.df_row, extra_afun_params$.var) + + # Get and check statistical names + .stat_names <- get_stat_names(x_stats, .stat_names) + + in_rows( + .list = x_stats, + .formats = .formats, + .names = .labels %>% .unlist_keep_nulls(), + .stat_names = .stat_names, + .labels = .labels %>% .unlist_keep_nulls(), + .indent_mods = .indent_mods %>% .unlist_keep_nulls() + ) +} #' @describeIn summarize_ancova Layout-creating function which can take statistics function arguments #' and additional format arguments. This function is a wrapper for [rtables::analyze()]. @@ -262,33 +302,50 @@ summarize_ancova <- function(lyt, show_labels = "visible", table_names = vars, .stats = NULL, - .formats = NULL, + .stat_names = NULL, + .formats = list( + "n" = "xx", + "lsmean" = "xx.xx", + "lsmean_diff" = "xx.xx", + "lsmean_diff_ci" = "(xx.xx, xx.xx)", + "pval" = "x.xxxx | (<0.0001)" + ), .labels = NULL, - .indent_mods = NULL) { - extra_args <- list( - variables = variables, conf_level = conf_level, interaction_y = interaction_y, - interaction_item = interaction_item, ... - ) + .indent_mods = list( + "n" = 0L, + "lsmean" = 0L, + "lsmean_diff" = 0L, + "lsmean_diff_ci" = 1L, + "pval" = 1L + )) { + # Process standard extra arguments + extra_args <- list(".stats" = .stats) + if (!is.null(.stat_names)) extra_args[[".stat_names"]] <- .stat_names + if (!is.null(.formats)) extra_args[[".formats"]] <- .formats + if (!is.null(.labels)) extra_args[[".labels"]] <- .labels + if (!is.null(.indent_mods)) extra_args[[".indent_mods"]] <- .indent_mods - afun <- make_afun( - a_ancova, - interaction_y = interaction_y, - interaction_item = interaction_item, - .stats = .stats, - .formats = .formats, - .labels = .labels, - .indent_mods = .indent_mods + # Process additional arguments to the statistic function + extra_args <- c( + extra_args, + variables = list(variables), conf_level = list(conf_level), interaction_y = list(interaction_y), + interaction_item = list(interaction_item), + ... ) + # Append additional info from layout to the analysis function + extra_args[[".additional_fun_parameters"]] <- get_additional_afun_params(add_alt_df = FALSE) + formals(a_ancova) <- c(formals(a_ancova), extra_args[[".additional_fun_parameters"]]) + analyze( - lyt, - vars, - var_labels = var_labels, - show_labels = show_labels, - table_names = table_names, - afun = afun, + lyt = lyt, + vars = vars, + afun = a_ancova, na_str = na_str, nested = nested, - extra_args = extra_args + extra_args = extra_args, + var_labels = var_labels, + show_labels = show_labels, + table_names = table_names ) } From c5cc9d08d416774bd41456813e6f53a6d9c75506 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:37:07 -0500 Subject: [PATCH 05/13] Clean up --- R/summarize_ancova.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index c685df234f..394516803e 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -220,7 +220,6 @@ a_ancova <- function(df, extra_afun_params <- retrieve_extra_afun_params(names(dots_extra_args$.additional_fun_parameters)) dots_extra_args$.additional_fun_parameters <- NULL - # browser() # Apply statistics function x_stats <- .apply_stat_functions( default_stat_fnc = s_ancova, @@ -243,7 +242,6 @@ a_ancova <- function(df, ) .indent_mods <- get_indents_from_stats(.stats, .indent_mods, levels_per_stats) - # Auto format handling .formats <- apply_auto_formatting(.formats, x_stats, extra_afun_params$.df_row, extra_afun_params$.var) From 495f2ea72cdc89089972f4e1c1aa4ebed378688a Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 12:39:25 -0500 Subject: [PATCH 06/13] Update docs --- man/summarize_ancova.Rd | 29 +++++++++++++++++------------ man/summarize_glm_count.Rd | 30 ++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/man/summarize_ancova.Rd b/man/summarize_ancova.Rd index b4ea31316a..ffd86d69de 100644 --- a/man/summarize_ancova.Rd +++ b/man/summarize_ancova.Rd @@ -20,33 +20,35 @@ summarize_ancova( show_labels = "visible", table_names = vars, .stats = NULL, - .formats = NULL, + .stat_names = NULL, + .formats = list(n = "xx", lsmean = "xx.xx", lsmean_diff = "xx.xx", lsmean_diff_ci = + "(xx.xx, xx.xx)", pval = "x.xxxx | (<0.0001)"), .labels = NULL, - .indent_mods = NULL + .indent_mods = list(n = 0L, lsmean = 0L, lsmean_diff = 0L, lsmean_diff_ci = 1L, pval = + 1L) ) s_ancova( df, .var, .df_row, - variables, .ref_group, .in_ref_col, + variables, conf_level, interaction_y = FALSE, - interaction_item = NULL + interaction_item = NULL, + ... ) a_ancova( df, - .var, - .df_row, - variables, - .ref_group, - .in_ref_col, - conf_level, - interaction_y = FALSE, - interaction_item = NULL + ..., + .stats = NULL, + .stat_names = NULL, + .formats = NULL, + .labels = NULL, + .indent_mods = NULL ) } \arguments{ @@ -89,6 +91,9 @@ times, to avoid warnings from \code{rtables}.} Options are: \verb{'n', 'lsmean', 'lsmean_diff', 'lsmean_diff_ci', 'pval'}} +\item{.stat_names}{(\code{character})\cr names of the statistics that are passed directly to name single statistics +(\code{.stats}). This option is visible when producing \code{\link[rtables:data.frame_export]{rtables::as_result_df()}} with \code{make_ard = TRUE}.} + \item{.formats}{(named \code{character} or \code{list})\cr formats for the statistics. See Details in \code{analyze_vars} for more information on the \code{"auto"} setting.} diff --git a/man/summarize_glm_count.Rd b/man/summarize_glm_count.Rd index 35292c54f3..868c3c5e58 100644 --- a/man/summarize_glm_count.Rd +++ b/man/summarize_glm_count.Rd @@ -3,6 +3,7 @@ \name{summarize_glm_count} \alias{summarize_glm_count} \alias{s_glm_count} +\alias{a_glm_count} \title{Summarize Poisson negative binomial regression} \usage{ summarize_glm_count( @@ -21,24 +22,36 @@ summarize_glm_count( show_labels = "visible", table_names = vars, .stats = get_stats("summarize_glm_count"), + .stat_names = NULL, .formats = NULL, .labels = NULL, - .indent_mods = c(n = 0L, rate = 0L, rate_ci = 1L, rate_ratio = 0L, rate_ratio_ci = 1L, - pval = 1L) + .indent_mods = list(n = 0L, rate = 0L, rate_ci = 1L, rate_ratio = 0L, rate_ratio_ci = + 1L, pval = 1L) ) s_glm_count( df, .var, .df_row, - variables, .ref_group, .in_ref_col, + variables, distribution, conf_level, rate_mean_method, weights, - scale = 1 + scale = 1, + ... +) + +a_glm_count( + df, + ..., + .stats = NULL, + .stat_names = NULL, + .formats = NULL, + .labels = NULL, + .indent_mods = NULL ) } \arguments{ @@ -90,6 +103,9 @@ times, to avoid warnings from \code{rtables}.} Options are: \verb{'n', 'rate', 'rate_ci', 'rate_ratio', 'rate_ratio_ci', 'pval'}} +\item{.stat_names}{(\code{character})\cr names of the statistics that are passed directly to name single statistics +(\code{.stats}). This option is visible when producing \code{\link[rtables:data.frame_export]{rtables::as_result_df()}} with \code{make_ard = TRUE}.} + \item{.formats}{(named \code{character} or \code{list})\cr formats for the statistics. See Details in \code{analyze_vars} for more information on the \code{"auto"} setting.} @@ -128,6 +144,10 @@ the statistics from \code{s_glm_count()} to the table layout. \item \code{pval}: p-value. } } + +\itemize{ +\item \code{a_glm_count()} returns the corresponding list with formatted \code{\link[rtables:CellValue]{rtables::CellValue()}}. +} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} @@ -161,6 +181,8 @@ and additional format arguments. This function is a wrapper for \code{\link[rtab \item \code{s_glm_count()}: Statistics function that produces a named list of results of the investigated Poisson model. +\item \code{a_glm_count()}: Formatted analysis function which is used as \code{afun} in \code{summarize_glm_count()}. + }} \examples{ library(dplyr) From 38167433dfb5c9d4525c527ad4a9d7dc25048cf0 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 19:36:15 -0500 Subject: [PATCH 07/13] Don't need levels_per_stats --- R/summarize_ancova.R | 8 +++----- R/summarize_glm_count.R | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index 394516803e..7bc85d8537 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -233,14 +233,12 @@ a_ancova <- function(df, # Fill in formatting defaults .stats <- get_stats("summarize_ancova", stats_in = .stats) - levels_per_stats <- as.list(.stats) %>% setNames(.stats) x_stats <- x_stats[.stats] - .formats <- get_formats_from_stats(.stats, .formats, levels_per_stats) + .formats <- get_formats_from_stats(.stats, .formats) .labels <- get_labels_from_stats( - .stats, .labels, levels_per_stats, - tern_defaults = c(lapply(x_stats[names(x_stats) != "n"], attr, "label"), tern_default_labels) + .stats, .labels, tern_defaults = c(lapply(x_stats[names(x_stats) != "n"], attr, "label"), tern_default_labels) ) - .indent_mods <- get_indents_from_stats(.stats, .indent_mods, levels_per_stats) + .indent_mods <- get_indents_from_stats(.stats, .indent_mods) # Auto format handling .formats <- apply_auto_formatting(.formats, x_stats, extra_afun_params$.df_row, extra_afun_params$.var) diff --git a/R/summarize_glm_count.R b/R/summarize_glm_count.R index e34bb347c1..382ed5b1f9 100644 --- a/R/summarize_glm_count.R +++ b/R/summarize_glm_count.R @@ -306,10 +306,9 @@ a_glm_count <- function(df, # Fill in formatting defaults .stats <- get_stats("summarize_glm_count", stats_in = .stats) - levels_per_stats <- as.list(.stats) %>% setNames(.stats) - .formats <- get_formats_from_stats(.stats, .formats, levels_per_stats) - .labels <- get_labels_from_stats(.stats, .labels, levels_per_stats) - .indent_mods <- get_indents_from_stats(.stats, .indent_mods, levels_per_stats) + .formats <- get_formats_from_stats(.stats, .formats) + .labels <- get_labels_from_stats(.stats, .labels) + .indent_mods <- get_indents_from_stats(.stats, .indent_mods) x_stats <- x_stats[.stats] From 64a60c05189a108e98b29caf80755e0748650d54 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 00:38:32 +0000 Subject: [PATCH 08/13] [skip style] [skip vbump] Restyle files --- R/summarize_ancova.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index 7bc85d8537..a7ebc4fe2c 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -236,7 +236,8 @@ a_ancova <- function(df, x_stats <- x_stats[.stats] .formats <- get_formats_from_stats(.stats, .formats) .labels <- get_labels_from_stats( - .stats, .labels, tern_defaults = c(lapply(x_stats[names(x_stats) != "n"], attr, "label"), tern_default_labels) + .stats, .labels, + tern_defaults = c(lapply(x_stats[names(x_stats) != "n"], attr, "label"), tern_default_labels) ) .indent_mods <- get_indents_from_stats(.stats, .indent_mods) From 75f62cba847e1a88fd686a65193381dca6f00165 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 19 Feb 2025 20:12:17 -0500 Subject: [PATCH 09/13] Clean up defaults --- R/summarize_ancova.R | 18 +++--------------- R/summarize_glm_count.R | 11 ++--------- R/utils_default_stats_formats_labels.R | 5 ++++- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index a7ebc4fe2c..ecf3af3bb6 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -298,23 +298,11 @@ summarize_ancova <- function(lyt, ..., show_labels = "visible", table_names = vars, - .stats = NULL, + .stats = c("n", "lsmean", "lsmean_diff", "lsmean_diff_ci", "pval"), .stat_names = NULL, - .formats = list( - "n" = "xx", - "lsmean" = "xx.xx", - "lsmean_diff" = "xx.xx", - "lsmean_diff_ci" = "(xx.xx, xx.xx)", - "pval" = "x.xxxx | (<0.0001)" - ), + .formats = NULL, .labels = NULL, - .indent_mods = list( - "n" = 0L, - "lsmean" = 0L, - "lsmean_diff" = 0L, - "lsmean_diff_ci" = 1L, - "pval" = 1L - )) { + .indent_mods = list("lsmean_diff_ci" = 1L, "pval" = 1L)) { # Process standard extra arguments extra_args <- list(".stats" = .stats) if (!is.null(.stat_names)) extra_args[[".stat_names"]] <- .stat_names diff --git a/R/summarize_glm_count.R b/R/summarize_glm_count.R index 382ed5b1f9..9c348ef29f 100644 --- a/R/summarize_glm_count.R +++ b/R/summarize_glm_count.R @@ -117,18 +117,11 @@ summarize_glm_count <- function(lyt, ..., show_labels = "visible", table_names = vars, - .stats = get_stats("summarize_glm_count"), + .stats = c("n", "rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), .stat_names = NULL, .formats = NULL, .labels = NULL, - .indent_mods = list( - "n" = 0L, - "rate" = 0L, - "rate_ci" = 1L, - "rate_ratio" = 0L, - "rate_ratio_ci" = 1L, - "pval" = 1L - )) { + .indent_mods = list("rate_ci" = 1L, "rate_ratio_ci" = 1L, "pval" = 1L)) { checkmate::assert_choice(rate_mean_method, c("emmeans", "ppmeans")) # Process standard extra arguments diff --git a/R/utils_default_stats_formats_labels.R b/R/utils_default_stats_formats_labels.R index 84dba5b9ac..fe1dbeae0a 100644 --- a/R/utils_default_stats_formats_labels.R +++ b/R/utils_default_stats_formats_labels.R @@ -590,7 +590,10 @@ tern_default_formats <- c( rate = "xx.xxxx", rate_ci = "(xx.xxxx, xx.xxxx)", rate_ratio = "xx.xxxx", - rate_ratio_ci = "(xx.xxxx, xx.xxxx)" + rate_ratio_ci = "(xx.xxxx, xx.xxxx)", + lsmean = "xx.xx", + lsmean_diff = "xx.xx", + lsmean_diff_ci = "(xx.xx, xx.xx)" ) # tern_default_labels ---------------------------------------------------------- From 054a7bdd12b8a219eb3ac812b83cf374d044d3d3 Mon Sep 17 00:00:00 2001 From: Joe Zhu Date: Thu, 20 Feb 2025 09:23:50 +0800 Subject: [PATCH 10/13] Empty-Commit From 28ec8690023d7944b9ca42cbe37f8abfda07e4f3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 22:11:54 +0000 Subject: [PATCH 11/13] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/summarize_ancova.Rd | 8 +++----- man/summarize_glm_count.Rd | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/man/summarize_ancova.Rd b/man/summarize_ancova.Rd index ffd86d69de..b9aa570c26 100644 --- a/man/summarize_ancova.Rd +++ b/man/summarize_ancova.Rd @@ -19,13 +19,11 @@ summarize_ancova( ..., show_labels = "visible", table_names = vars, - .stats = NULL, + .stats = c("n", "lsmean", "lsmean_diff", "lsmean_diff_ci", "pval"), .stat_names = NULL, - .formats = list(n = "xx", lsmean = "xx.xx", lsmean_diff = "xx.xx", lsmean_diff_ci = - "(xx.xx, xx.xx)", pval = "x.xxxx | (<0.0001)"), + .formats = NULL, .labels = NULL, - .indent_mods = list(n = 0L, lsmean = 0L, lsmean_diff = 0L, lsmean_diff_ci = 1L, pval = - 1L) + .indent_mods = list(lsmean_diff_ci = 1L, pval = 1L) ) s_ancova( diff --git a/man/summarize_glm_count.Rd b/man/summarize_glm_count.Rd index 868c3c5e58..b694dc322a 100644 --- a/man/summarize_glm_count.Rd +++ b/man/summarize_glm_count.Rd @@ -21,12 +21,11 @@ summarize_glm_count( ..., show_labels = "visible", table_names = vars, - .stats = get_stats("summarize_glm_count"), + .stats = c("n", "rate", "rate_ci", "rate_ratio", "rate_ratio_ci", "pval"), .stat_names = NULL, .formats = NULL, .labels = NULL, - .indent_mods = list(n = 0L, rate = 0L, rate_ci = 1L, rate_ratio = 0L, rate_ratio_ci = - 1L, pval = 1L) + .indent_mods = list(rate_ci = 1L, rate_ratio_ci = 1L, pval = 1L) ) s_glm_count( From cc6803f48f98a7809c22b16e0c1c23e11e566c18 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 20 Feb 2025 17:25:01 -0500 Subject: [PATCH 12/13] Fix lint --- R/utils_default_stats_formats_labels.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils_default_stats_formats_labels.R b/R/utils_default_stats_formats_labels.R index fe1dbeae0a..ebbe6dc98e 100644 --- a/R/utils_default_stats_formats_labels.R +++ b/R/utils_default_stats_formats_labels.R @@ -157,7 +157,7 @@ get_stat_names <- function(stat_results, stat_names_in = NULL) { if (is.null(nm)) { nm <- rep(NA_character_, length(si)) # no statistical names } - return(nm) + nm }) # Modify some with custom stat names From 54a711a8b93aa44d3ba9462ed4b3c07cab9235c0 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Mon, 24 Feb 2025 15:17:55 -0500 Subject: [PATCH 13/13] Re-add custom stat function option --- R/summarize_ancova.R | 9 +++++++-- R/summarize_glm_count.R | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index ecf3af3bb6..82dda6f85b 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -220,10 +220,15 @@ a_ancova <- function(df, extra_afun_params <- retrieve_extra_afun_params(names(dots_extra_args$.additional_fun_parameters)) dots_extra_args$.additional_fun_parameters <- NULL + # Check for user-defined functions + default_and_custom_stats_list <- .split_std_from_custom_stats(.stats) + .stats <- default_and_custom_stats_list$default_stats + custom_stat_functions <- default_and_custom_stats_list$custom_stats + # Apply statistics function x_stats <- .apply_stat_functions( default_stat_fnc = s_ancova, - custom_stat_fnc_list = NULL, + custom_stat_fnc_list = custom_stat_functions, args_list = c( df = list(df), extra_afun_params, @@ -232,7 +237,7 @@ a_ancova <- function(df, ) # Fill in formatting defaults - .stats <- get_stats("summarize_ancova", stats_in = .stats) + .stats <- c(get_stats("summarize_ancova", stats_in = .stats), names(custom_stat_functions)) x_stats <- x_stats[.stats] .formats <- get_formats_from_stats(.stats, .formats) .labels <- get_labels_from_stats( diff --git a/R/summarize_glm_count.R b/R/summarize_glm_count.R index 9c348ef29f..95b4005bb6 100644 --- a/R/summarize_glm_count.R +++ b/R/summarize_glm_count.R @@ -286,10 +286,15 @@ a_glm_count <- function(df, extra_afun_params <- retrieve_extra_afun_params(names(dots_extra_args$.additional_fun_parameters)) dots_extra_args$.additional_fun_parameters <- NULL + # Check for user-defined functions + default_and_custom_stats_list <- .split_std_from_custom_stats(.stats) + .stats <- default_and_custom_stats_list$default_stats + custom_stat_functions <- default_and_custom_stats_list$custom_stats + # Apply statistics function x_stats <- .apply_stat_functions( default_stat_fnc = s_glm_count, - custom_stat_fnc_list = NULL, + custom_stat_fnc_list = custom_stat_functions, args_list = c( df = list(df), extra_afun_params, @@ -298,7 +303,7 @@ a_glm_count <- function(df, ) # Fill in formatting defaults - .stats <- get_stats("summarize_glm_count", stats_in = .stats) + .stats <- c(get_stats("summarize_glm_count", stats_in = .stats), names(custom_stat_functions)) .formats <- get_formats_from_stats(.stats, .formats) .labels <- get_labels_from_stats(.stats, .labels) .indent_mods <- get_indents_from_stats(.stats, .indent_mods)