Hi!
I used RStudio quite a bit but I am new to using RMarkdown.
I created an .Rmd file to create .pdf-reports. It includes text, R-chunks with ggplot2-plots and tables like:
```{r}
cars <- mtcars[rownames(mtcars)==car,]
m <- as.matrix(cars)
m
kable(m,format="latex",booktabs=TRUE,align="c") %>%
kable_styling(full_width = T,font_size = 20)
rm(m)
and it works fine when knitting it to pdf!!!
But if I run it from a simple R script (I need to do that as I want to create many of these reports from within a loop) and use
```{r}
for (car in unique(rownames(mtcars))){
rmarkdown::render(input = "test.Rmd",
output_format = "pdf_document",
output_file = paste("test_report_", car, Sys.Date(), ".pdf", sep=''))
}
it does not work anymore.
I will get this error:
! LaTeX Error: Environment tabu undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.141 \begin{tabu}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test_2.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test_2.pdf --template "C:\Users\NK\Documents\R\win-library\3.4\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
I loeaded all needed packages in both R and Rmd-file.
library(knitr)
library(markdown)
library(rmarkdown)
library(kableExtra)
But somehow it wants me to define an environment for the table I create with kable. How can I do that? It took me quite some time to adapt the layout for my tables and plots in the .Rmd file and now R does not seem to recognize any of it.