From e479da7128bd1b9bb9fa353ac0d81521e96d63bc Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sat, 9 Mar 2024 08:08:04 -0500 Subject: [PATCH] balance bottom num --- R/datasummary_balance.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/datasummary_balance.R b/R/datasummary_balance.R index 4d7824a0d..3d06f1707 100644 --- a/R/datasummary_balance.R +++ b/R/datasummary_balance.R @@ -133,15 +133,19 @@ datasummary_balance <- function(formula, tmp1$bad_factor_for_stub <- as.factor(sample(c("A", "B"), nrow(tmp1), replace = TRUE)) tmp2$bad_factor_for_stub <- as.factor(sample(c("A", "B"), nrow(tmp2), replace = TRUE)) - pctformat = function(x) sprintf("%.1f", x) + # pctformat = function(x) sprintf("%.1f", x) + pctformat <- sanitize_fmt(1) + nformat <- function(x) { + sanitize_fmt(0)(as.numeric(x)) + } if (!is.null(rhs)) { f_fac <- stats::as.formula(sprintf( "All(tmp2, factor = TRUE, numeric = FALSE) ~ - Factor(%s) * (N + Heading('Pct.') * Percent('col') * Format(pctformat()))", rhs)) + Factor(%s) * (N * Format(nformat()) + Heading('Pct.') * Percent('col') * Format(pctformat()))", rhs)) } else { f_fac <- stats::as.formula( "All(tmp2, factor = TRUE, numeric = FALSE) ~ - (N + Heading('Pct.') * Percent('col') * Format(pctformat()))") + (N * Format(nformat()) + Heading('Pct.') * Percent('col') * Format(pctformat()))") } tab_fac <- datasummary(formula = f_fac, data = tmp1, @@ -326,7 +330,6 @@ DinM <- function(lhs, rhs, data, fmt, statistic, stars = TRUE, escape = TRUE) { out <- estimatr::tidy(out) -settings_set("junk", TRUE) rounding <- sanitize_fmt(fmt) out[["estimate"]] <- rounding(out[["estimate"]])