From 4397dd21af9b2b96162e21ff55d6f93b6c818d01 Mon Sep 17 00:00:00 2001 From: Brandon Bertelsen Date: Fri, 18 Feb 2022 16:57:52 -0500 Subject: [PATCH 1/3] Fixes regression with pagebreak_in_banner --- NEWS.md | 4 ++++ R/writeLatex.R | 13 +++++-------- tests/testthat/test-catArrayToCategoricals.R | 5 ++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 211ece1..e11b014 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## crunchtabs 1.4.4 + +- Fixes a regression where absolutelynopagebreak was duplicated 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) diff --git a/R/writeLatex.R b/R/writeLatex.R index f7fe4cd..ce897d3 100644 --- a/R/writeLatex.R +++ b/R/writeLatex.R @@ -222,14 +222,11 @@ 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 <- noBreaks(table) } table_bodies[[i]] <- table diff --git a/tests/testthat/test-catArrayToCategoricals.R b/tests/testthat/test-catArrayToCategoricals.R index 4577f9a..cab1a02 100644 --- a/tests/testthat/test-catArrayToCategoricals.R +++ b/tests/testthat/test-catArrayToCategoricals.R @@ -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, From f9cb9278a7f459c6719d68145b809574647cda53 Mon Sep 17 00:00:00 2001 From: Brandon Bertelsen Date: Tue, 22 Feb 2022 13:40:32 -0500 Subject: [PATCH 2/3] Alternative approach for pagebreak_in_banner --- R/tex-table.R | 12 ++++++++---- R/writeLatex.R | 6 +++--- tests/testthat/test-write-latex.R | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/R/tex-table.R b/R/tex-table.R index d6661da..530310a 100644 --- a/R/tex-table.R +++ b/R/tex-table.R @@ -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" @@ -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, diff --git a/R/writeLatex.R b/R/writeLatex.R index ce897d3..b7bad44 100644 --- a/R/writeLatex.R +++ b/R/writeLatex.R @@ -222,13 +222,13 @@ latexReportTables <- function(results, banner, theme) { # bottomrule gets wiped out by nopagebreak environment # adding one manually if (!theme$pagebreak_in_banner) { - table = gsub( + table <- gsub( "\\end{longtable}", - "\\bottomrule\\end{longtable}\n\\end{absolutelynopagebreak}", + "\\bottomrule\\end{longtable}\n", # \\end{absolutelynopagebreak}", table, fixed = TRUE) - # table <- noBreaks(table) } + table_bodies[[i]] <- table } diff --git a/tests/testthat/test-write-latex.R b/tests/testthat/test-write-latex.R index a1073a9..a396e30 100644 --- a/tests/testthat/test-write-latex.R +++ b/tests/testthat/test-write-latex.R @@ -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 From 3a4005d67d0086664a8c6e97aa7ca3e2c3654f65 Mon Sep 17 00:00:00 2001 From: Brandon Bertelsen Date: Wed, 23 Feb 2022 08:45:57 -0500 Subject: [PATCH 3/3] Update description and news --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a8d5886..ece643e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 () 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"), diff --git a/NEWS.md b/NEWS.md index e11b014..094d400 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ ## crunchtabs 1.4.4 -- Fixes a regression where absolutelynopagebreak was duplicated in some situations. (pagebreak_in_banner=TRUE and one_per_page=FALSE) +- 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