1
votes

I wrote an rmd file in RStudio and cannot seem to get a PDF to knit if any tables are in the body of the text. I tried making a super simple test rmd to verify that the table was the one causing the error.

---
title: "test"
output: pdf_document
---

| Right | Left | Default | Center | 
|------:|:-----|---------|:------:| 
| 12 | 12 | 12 | 12 | 
| 123 | 123 | 123 | 123 | 
| 1 | 1 | 1 | 1 |

Here is the error I get when I try to knit.

Output created: test.pdf Error in tools::file_path_as_absolute(output_file) : file 'test.pdf' does not exist Calls: -> In addition: Warning messages: 1: running command '"pdflatex" -halt-on-error -interaction=batchmode "test.tex"' had status 1 2: In readLines(logfile) : incomplete final line found on 'test.log' Execution halted

Here is my session info:

R version 3.4.4 (2018-03-15) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C
LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils
datasets methods base

other attached packages: [1] rmarkdown_1.9 magrittr_1.5
flextable_0.4.3 knitr_1.20

loaded via a namespace (and not attached): [1] Rcpp_0.12.16
digest_0.6.15 rprojroot_1.3-2 R.methodsS3_1.7.1 R6_2.2.2
backports_1.1.2 evaluate_0.10.1 zip_1.0.0 [9] gdtools_0.1.7 stringi_1.1.7 uuid_0.1-2 R.oo_1.21.0
R.utils_2.6.0 xml2_1.2.0 tools_3.4.4 stringr_1.3.0
[17] officer_0.2.2 yaml_2.1.18 compiler_3.4.4
base64enc_0.1-3 htmltools_0.3.6

1

1 Answers

3
votes

Try my new absolute favorite thing, flextable - it renders to HTML and PDF without the pain of knitting using other methods:

```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(knitr)
library(flextable)
library(magrittr)
row1 <- c(12,12,12,12)
row2 <- c(123,123,123,123)
row3 <- c(1,1,1,1)
df <- as.data.frame(rbind(row1,row2,row3))
names(df) <- c("Right","Left","Default","Center")
df %>% regulartable() %>% autofit()
```

It produces this in both HTML and PDF:

flex3