From f93e88eddd816cd6d976ba6408fa08ea44ce4631 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 29 Jan 2025 11:02:00 -0500 Subject: [PATCH 1/3] Remove the `ungroup_stats()` function --- NEWS.md | 3 +++ R/utils_factor.R | 41 ----------------------------------------- man/ungroup_stats.Rd | 27 --------------------------- 3 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 man/ungroup_stats.Rd diff --git a/NEWS.md b/NEWS.md index 785b416b8d..1af83e47af 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ ### Bug Fixes * Fixed bug in `a_count_patients_with_flags()` preventing select custom label and indentation specification formats from being applied. +### Miscellaneous +* Removed internal function `ungroup_stats()` and replaced its usage with the `get_*_from_stats()` functions. + # tern 0.9.7 ### Enhancements diff --git a/R/utils_factor.R b/R/utils_factor.R index 1c04847549..669bb93279 100644 --- a/R/utils_factor.R +++ b/R/utils_factor.R @@ -276,44 +276,3 @@ fct_collapse_only <- function(.f, ..., .na_level = "") { x <- forcats::fct_collapse(.f, ..., other_level = .na_level) do.call(forcats::fct_relevel, args = c(list(.f = x), as.list(new_lvls))) } - -#' Ungroup non-numeric statistics -#' -#' Ungroups grouped non-numeric statistics within input vectors `.formats`, `.labels`, and `.indent_mods`. -#' -#' @inheritParams argument_convention -#' @param stat_out (named `list` of `numeric`)\cr list of numeric statistics containing the statistics to ungroup. -#' -#' @return A `list` with modified elements `stat_out`, `.formats`, `.labels`, `.levels`, and `.indent_mods`. -#' -#' @seealso [a_summary()] which uses this function internally. -#' -#' @keywords internal -ungroup_stats <- function(stat_out, - .formats, - .indent_mods) { - checkmate::assert_list(stat_out) - empty_pval <- "pval" %in% names(stat_out) && length(stat_out[["pval"]]) == 0 - empty_pval_counts <- "pval_counts" %in% names(stat_out) && length(stat_out[["pval_counts"]]) == 0 - stat_out <- unlist(stat_out, recursive = FALSE) - - # If p-value is empty it is removed by unlist and needs to be re-added - if (empty_pval) stat_out[["pval"]] <- character() - if (empty_pval_counts) stat_out[["pval_counts"]] <- character() - .stats <- sapply(regmatches(names(stat_out), regexpr("\\.", names(stat_out)), invert = TRUE), function(xi) xi[[1]]) - - # Ungroup stats - .formats <- lapply(.stats, function(x) { - .formats[[if (!grepl("\\.", x)) x else regmatches(x, regexpr("\\.", x), invert = TRUE)[[1]][1]]] - }) - - .indent_mods <- sapply(.stats, function(x) { - .indent_mods[[if (!grepl("\\.", x)) x else regmatches(x, regexpr("\\.", x), invert = TRUE)[[1]][1]]] - }) - - list( - x = stat_out, - .formats = .formats, - .indent_mods = .indent_mods - ) -} diff --git a/man/ungroup_stats.Rd b/man/ungroup_stats.Rd deleted file mode 100644 index 0a6241a18f..0000000000 --- a/man/ungroup_stats.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils_factor.R -\name{ungroup_stats} -\alias{ungroup_stats} -\title{Ungroup non-numeric statistics} -\usage{ -ungroup_stats(stat_out, .formats, .indent_mods) -} -\arguments{ -\item{stat_out}{(named \code{list} of \code{numeric})\cr list of numeric statistics containing the statistics to ungroup.} - -\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.} - -\item{.indent_mods}{(named \code{integer})\cr indent modifiers for the labels. Defaults to 0, which corresponds to the -unmodified default behavior. Can be negative.} -} -\value{ -A \code{list} with modified elements \code{stat_out}, \code{.formats}, \code{.labels}, \code{.levels}, and \code{.indent_mods}. -} -\description{ -Ungroups grouped non-numeric statistics within input vectors \code{.formats}, \code{.labels}, and \code{.indent_mods}. -} -\seealso{ -\code{\link[=a_summary]{a_summary()}} which uses this function internally. -} -\keyword{internal} From e14be8e08006fe08e59f9ad20aada108612b78ef Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 29 Jan 2025 11:50:45 -0500 Subject: [PATCH 2/3] Fix failing integration test --- tests/testthat/test-analyze_variables.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-analyze_variables.R b/tests/testthat/test-analyze_variables.R index 891d73321d..6fcb0fe4f2 100644 --- a/tests/testthat/test-analyze_variables.R +++ b/tests/testthat/test-analyze_variables.R @@ -584,12 +584,10 @@ testthat::test_that("analyze_vars works well with additional stat names (.stat_n # format for v is correctly printed (added external statistic) testthat::expect_equal( - as_result_df(res, data_format = "strings")[nrow(res2), ncol(res2)], + as_result_df(res, data_format = "strings")[["all obs"]][nrow(res2)], c("0.00") # i.e. x.xx ) -}) -testthat::test_that("analyze_vars works well with additional stat names (.stat_names) and stats (custom fnc)", { - dt <- data.frame("VAR" = c(0.001, 0.2, 0.0011000, 3, 4), "VAR2" = letters[seq(5)]) + res <- basic_table() %>% analyze_vars( vars = c("VAR", "VAR2"), From 66be144a5beab3050fcce16c33254f592235e74a Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Wed, 29 Jan 2025 11:51:28 -0500 Subject: [PATCH 3/3] Add a project ID - needed for R 4.4.2+ --- tern.Rproj | 1 + 1 file changed, 1 insertion(+) diff --git a/tern.Rproj b/tern.Rproj index 4f69393588..a8fcecc6fb 100644 --- a/tern.Rproj +++ b/tern.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 9441de74-2fb5-42be-9c7a-c2a704b8aa93 RestoreWorkspace: Default SaveWorkspace: Default