Skip to content

Commit

Permalink
Merge pull request #265 from Crunch-io/joe_round
Browse files Browse the repository at this point in the history
Joe round
  • Loading branch information
domjarkey authored Sep 22, 2022
2 parents bca3a76 + 732e348 commit e93f8a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 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
10 changes: 5 additions & 5 deletions tests/testthat/ref/tabbook1.tex
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@

\textbf{header} & & & & & \\
Cat & 30\% & 38\% & 25\% & 18\% & 44\% \\
\textbf{Net: Cat/Bird} & \textbf{50\%} & \textbf{38\%} & \textbf{58\%} & \textbf{30\%} & \textbf{73\%} \\
\textbf{Net: Cat/Bird} & \textbf{50\%} & \textbf{38\%} & \textbf{58\%} & \textbf{31\%} & \textbf{73\%} \\
Dog & 50\% & 62\% & 42\% & 69\% & 27\% \\
\textbf{Net: Cat/Dog} & \textbf{80\%} & \textbf{100\%} & \textbf{67\%} & \textbf{87\%} & \textbf{71\%} \\
\textbf{Net: Cat/Dog} & \textbf{80\%} & \textbf{100\%} & \textbf{67\%} & \textbf{88\%} & \textbf{71\%} \\
Bird & 20\% & 0\% & 33\% & 12\% & 29\% \\
\midrule
Totals & 100\% & 100\% & 100\% & 99\% & 100\% \\
Expand Down Expand Up @@ -200,7 +200,7 @@
Cat & 49\% & 22\% & 66\% & 100\% & 26\% \\
Dog & 43\% & 56\% & 34\% & 0\% & 62\% \\
Bird & 9\% & 22\% & 0\% & 0\% & 13\% \\
\textbf{Net: Cat/Dog} & \textbf{92\%} & \textbf{78\%} & \textbf{100\%} & \textbf{100\%} & \textbf{88\%} \\
\textbf{Net: Cat/Dog} & \textbf{91\%} & \textbf{78\%} & \textbf{100\%} & \textbf{100\%} & \textbf{87\%} \\
\midrule
Totals & 101\% & 100\% & 100\% & 100\% & 101\% \\
Unweighted N & \multicolumn{1}{c}{11} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{8} & \multicolumn{1}{c}{5} & \multicolumn{1}{c}{6} \\
Expand All @@ -218,7 +218,7 @@
Cat & 49\% & 22\% & 100\% & 46\% \\
Dog & 43\% & 56\% & 0\% & 54\% \\
Bird & 9\% & 22\% & 0\% & 0\% \\
\textbf{Net: Cat/Dog} & \textbf{92\%} & \textbf{78\%} & \textbf{100\%} & \textbf{100\%} \\
\textbf{Net: Cat/Dog} & \textbf{91\%} & \textbf{78\%} & \textbf{100\%} & \textbf{100\%} \\
\midrule
Totals & 101\% & 100\% & 100\% & 100\% \\
Unweighted N & \multicolumn{1}{c}{11} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{6} \\
Expand All @@ -241,7 +241,7 @@
Cat & 42\% & 50\% & 36\% & 54\% & 18\% \\
Dog & 37\% & 14\% & 54\% & 46\% & 18\% \\
Bird & 21\% & 36\% & 11\% & 0\% & 64\% \\
\textbf{Net: Cat/Dog} & \textbf{79\%} & \textbf{64\%} & \textbf{90\%} & \textbf{100\%} & \textbf{36\%} \\
\textbf{Net: Cat/Dog} & \textbf{79\%} & \textbf{64\%} & \textbf{89\%} & \textbf{100\%} & \textbf{36\%} \\
\midrule
Totals & 100\% & 100\% & 101\% & 100\% & 100\% \\
Unweighted N & \multicolumn{1}{c}{16} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{12} & \multicolumn{1}{c}{9} & \multicolumn{1}{c}{7} \\
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/ref/topline1.tex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
\endfoot
\endlastfoot

& Home & 49\% & 43\% & 9\% & \textbf{92\%} \\
& Home & 49\% & 43\% & 9\% & \textbf{91\%} \\
& Work & 42\% & 37\% & 21\% & \textbf{79\%} \\

\end{longtable}
Expand Down

0 comments on commit e93f8a9

Please sign in to comment.