Skip to content

Commit

Permalink
balance bottom num
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Mar 9, 2024
1 parent 590a9eb commit e479da7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/datasummary_balance.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]])
Expand Down

0 comments on commit e479da7

Please sign in to comment.