|
17 | 17 | #' @param appendix Should categorical questions with greater than 20 categories be put in an apppendix? Defaults to TRUE. |
18 | 18 | #' @param logo Default to NULL. A character string one of: yougov or ygblue. Includes the logo automatically. Also accepts a path to a logo file. |
19 | 19 | #' @param position Defaults to NULL. Identifies the position of the table on the page. Accepts "c", "l", or "r". Default position is left aligned tables. |
| 20 | +#' @param path The path to place .tex and .pdf files. |
| 21 | +#' @param logging Leave logs in the working directory, defaults to FALSE |
20 | 22 | #' @param ... Additional arguments passed to \link[kableExtra]{kable_styling} Unused. |
| 23 | +#' |
21 | 24 | #' @export |
22 | 25 | writeCodeBookLatex <- function( |
23 | 26 | ds, url = NULL, rmd = TRUE, pdf = TRUE, title = NULL, subtitle = NULL, |
24 | 27 | table_of_contents = FALSE, sample_desc = NULL, field_period = NULL, |
25 | 28 | preamble = NULL, suppress_zero_counts = FALSE, appendix = TRUE, logo = NULL, |
26 | | - position = NULL, |
| 29 | + position = NULL, path = NULL, logging = FALSE, |
27 | 30 | ...) { |
28 | 31 |
|
29 | 32 | options("crunchtabs.codebook.suppress.zeros" = suppress_zero_counts) |
@@ -194,10 +197,31 @@ writeCodeBookLatex <- function( |
194 | 197 | # codebook <- gsub("\\begin{longtabu}", paste0("\\begin{longtabu}", replacement), codebook, fixed = TRUE) |
195 | 198 | } |
196 | 199 |
|
197 | | - write(codebook, gsub(" ","-", paste0(name(ds), ".tex"))) |
| 200 | + |
| 201 | + # Issue 185 - Specify a path |
| 202 | + if (!is.null(path)) { |
| 203 | + basename <- gsub(" ","-", name(ds)) |
| 204 | + texname <- paste0(path,"/", basename, ".tex") |
| 205 | + pdfname <- paste0(path, "/", basename, ".pdf") |
| 206 | + } else { |
| 207 | + basename <- gsub(" ","-", name(ds)) |
| 208 | + texname <- paste0(basename, ".tex") |
| 209 | + pdfname <- paste0(basename, ".pdf") |
| 210 | + } |
| 211 | + |
| 212 | + write(codebook, texname) |
198 | 213 |
|
199 | 214 | if (pdf) { |
200 | | - tinytex::pdflatex(gsub(" ","-", paste0(name(ds), ".tex"))) |
201 | | - file.open(paste0(gsub(" ","-", paste0(name(ds))), ".pdf")) |
| 215 | + tinytex::pdflatex(texname, pdf_file = pdfname) |
| 216 | + |
| 217 | + if (!logging) { |
| 218 | + files <- list.files(path = getwd()) |
| 219 | + files <- grep("out$|log$|aux$", files, value = TRUE) |
| 220 | + if (length(files)) { |
| 221 | + file.remove(file.path(getwd(), files)) |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + file.open(pdfname) |
202 | 226 | } |
203 | 227 | } |
0 commit comments