Skip to content

Commit

Permalink
Calculate tab insert before rounding occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
1beb committed May 12, 2022
1 parent 723e78a commit d9b6876
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R/reformatResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ reformatVar <- function(var, banner_name, theme, proportions, banner_info, latex
should_round <- ifelse(var$alias %in% theme$latex_round_percentages_exception,
!should_round, should_round
)

# Calculate tabInsertions before rounding!
if (var$type %in% c("categorical", "categorical_array") && dt %in% "body" &&
any(var$inserts %in% c("Heading", "Subtotal"))) {
data <- as.matrix(calcTabInsertions(data, var$inserts_obj, var$categories))
}

if (should_round & dt != "weighted_n") {
data[] <- apply(data, 2, roundPropCategorical, theme$digits)
} else if (!is.null(rdig) && !is.infinite(rdig)) {
Expand Down Expand Up @@ -232,10 +239,6 @@ reformatVar <- function(var, banner_name, theme, proportions, banner_info, latex
dimnames = list(c(theme$format_totals_row$name), colnames(data))
)
}
if (var$type %in% c("categorical", "categorical_array") && dt %in% "body" &&
any(var$inserts %in% c("Heading", "Subtotal"))) {
data <- as.matrix(calcTabInsertions(data, var$inserts_obj, var$categories))
}

if (weight_v && nrow(data) > 1) {
data <- rbind(apply(data, 2, min, na.rm = TRUE), apply(data, 2, max, na.rm = TRUE))
Expand Down

0 comments on commit d9b6876

Please sign in to comment.