Skip to content

Commit

Permalink
Merge pull request #262 from Crunch-io/INNOV-498-joe
Browse files Browse the repository at this point in the history
Fixes regression with pagebreak_in_banner
  • Loading branch information
1beb committed Feb 23, 2022
2 parents 35963db + 3a4005d commit 723e78a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: In order to generate custom survey reports, this package provides
'banners' (cross-tabulations) and codebooks of datasets in the Crunch
(<https://crunch.io/>) web service. Reports can be written in 'PDF' format
using 'LaTeX' or in Microsoft Excel '.xlsx' files.
Version: 1.4.3
Version: 1.4.4
Authors@R: c(
person("Persephone", "Tsebelis", role="aut"),
person("Kamil", "Sedrowicz", role="aut"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## crunchtabs 1.4.4

- Fixes a regression where absolutelynopagebreak was duplicated or not functional in some situations. (pagebreak_in_banner=TRUE and one_per_page=FALSE)

## crunchtabs 1.4.3

- categorical_arrays were previously spliced into the first position at every question iteration, leading to questions being presented out of vector order in the resulting pdf output. This update patches the results list back together when splicing the array questions in-place. Now, the order of variables is the same as the order presented in the output pdf. (INNOV-498)
Expand Down
12 changes: 8 additions & 4 deletions R/tex-table.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ latexTableBody <- function(df, theme, question_alias = NULL) {
rows <- apply(cbind(rownames(dt), dt), 1, paste, collapse = " & ")
}
# Add a newline to each row, then join in a single string
return(paste(rows, newline, collapse = "\n"))
if(!theme$pagebreak_in_banner) {
return(paste(rows, "\\\\*", collapse = "\n"))
} else {
return(paste(rows, newline, collapse = "\n"))
}
})

# Assemble the components of the table, based on "data_order"
Expand Down Expand Up @@ -275,9 +279,9 @@ tableHeader.CrossTabVar <- function(var, theme) {
}

nopagebreak <- NULL
if (!theme$pagebreak_in_banner) {
nopagebreak <- "\\begin{absolutelynopagebreak}"
}
# if (!theme$pagebreak_in_banner) {
# nopagebreak <- "\\begin{absolutelynopagebreak}"
# }

header <- paste(
nopagebreak,
Expand Down
13 changes: 5 additions & 8 deletions R/writeLatex.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,13 @@ latexReportTables <- function(results, banner, theme) {
# bottomrule gets wiped out by nopagebreak environment
# adding one manually
if (!theme$pagebreak_in_banner) {
# table <- gsub(
# "\\end{longtable}",
# "\\bottomrule\\end{longtable}\n",
# table,
# fixed = TRUE
# )

table <- noBreaks(table)
table <- gsub(
"\\end{longtable}",
"\\bottomrule\\end{longtable}\n", # \\end{absolutelynopagebreak}",
table, fixed = TRUE)
}


table_bodies[[i]] <- table
}

Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-catArrayToCategoricals.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ context("catArrayToCategoricals")

test_that("Binds categorical arrays appropriately", {
questions <- readRDS(test_path("fixtures/catArrayToCategorical_questions.rds"))
res <- catArrayToCategoricals(questions, "petloc", labels = NULL)
res <- expect_warning(
catArrayToCategoricals(questions, "petloc", labels = NULL),
"New variables derived from a"
)

expect_equal(
res$petloc_1$crosstabs$Results$`___total___`$proportions,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-write-latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ test_that("Adds nonTabBookSummary as expected", {

res <- latexReportTables(results, NULL, tema)

# Expect absolutelynopagebreak wraps on all
# Expect absolutelynopagebreak wraps on none!
expect_true(
all(grepl("absolutelynopagebreak", res))
all(!grepl("absolutelynopagebreak", res))
)

# Clear page not appended to results
Expand Down

0 comments on commit 723e78a

Please sign in to comment.