Skip to content

Commit

Permalink
Merge pull request #136 from Crunch-io/develop
Browse files Browse the repository at this point in the history
WIP: Release 1.2.6
  • Loading branch information
1beb authored May 17, 2020
2 parents 9e0594f + b7a029a commit 95638ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 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) 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.2.5
Version: 1.2.6
Authors@R: c(
person("Persephone", "Tsebelis", role="aut"),
person("Kamil", "Sedrowicz", role="aut"),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## crunchtabs 1.2.6

- tinytex enforcement does not respect logging = FALSE (#132)
- sorting for categoricals / multiple response in toplines (#104)
- sorting for crosstabs objects (#143)
- updated FAQ with sorting examples (#104)

## crunchtabs 1.2.5

* Add summarization for continuous variables (NumericVariable) in toplines (#80)
Expand Down
11 changes: 8 additions & 3 deletions R/writeLatex.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ writeLatex <- function(data_summary, theme = themeDefaultLatex(),
filename <- paste0(filename, ".tex")
cat(out, sep = "\n", file = filename)
if (pdf) {
if (logging) {
print("PDF-ing")
}
if ("tinytex" %in% rownames(installed.packages())) {
tinytex::pdflatex(filename, bib_engine = NULL)
if (!logging) {
files <- list.files(path = getwd())
files <- grep("out$|log$|aux$", files, value = TRUE)
if (length(files)) {
file.remove(file.path(getwd(), files))
}
}

if (open) {
file.open(gsub(".tex", ".pdf", filename, fixed = TRUE))
}
Expand Down
27 changes: 26 additions & 1 deletion tests/testthat/test-write-latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ test_that("LaTeX escaping", {
expect_identical(texEscape(bad_description), "Q. \\newline and")
})

test_that("Does not delete log/aux/out files if logging = TRUE", {
system("echo 'This is an out file' >> text.out")
system("echo 'This is a log file' >> text.log")
system("echo 'This is an aux file' >> text.aux")
writeLatex(cs, logging = TRUE, pdf = TRUE)
expect_true(file.exists("text.out"))
expect_true(file.exists("text.log"))
expect_true(file.exists("text.aux"))
})


test_that("Deletes log/aux/out files if logging = FALSE (the default)", {
system("echo 'This is an out file' >> text.out")
system("echo 'This is a log file' >> text.log")
system("echo 'This is an aux file' >> text.aux")

expect_true(file.exists("text.out"))
expect_true(file.exists("text.log"))
expect_true(file.exists("text.aux"))
writeLatex(cs, pdf = TRUE, logging = FALSE)
expect_true(!file.exists("text.out"))
expect_true(!file.exists("text.log"))
expect_true(!file.exists("text.aux"))
})

with_temp_dir({
test_that("Write Latex error handling", {
expect_error(writeLatex("stuff"))
Expand Down Expand Up @@ -43,7 +68,7 @@ with_temp_dir({
skip_on_appveyor()
writeLatex(cs, pdf = TRUE)
expect_true(file.exists("Example Dataset with Nets.pdf"))
expect_output(writeLatex(cs, pdf = TRUE, logging = TRUE), "PDF-ing")
# expect_output(writeLatex(cs, pdf = TRUE, logging = TRUE), "PDF-ing") # Kind of useless just for one tiny message
writeLatex(cs, subtitle = "something", pdf = TRUE)
writeLatex(cs, sample_desc = "Adults", pdf = TRUE)
writeLatex(cs, moe = 0.2, field_period = "2018-01-01 to 2018-01-02", pdf = TRUE)
Expand Down

0 comments on commit 95638ec

Please sign in to comment.