Previously, I have generated multiple reports in .Rnw format to .pdf in R via the knit2pdf() command. However, today I am facing the following problem, I will detail it by steps:
- I am building a project with Bookdown.
- In the Index.Rmd file I want to include a chunk that calls a script called reports.R, which converts various .Rnw files to .pdf.
- I want this to happen when I press "Build Book".
- The generated pdf files do not correctly display the code snippets used in the chunks.
- If I execute the conversion manually with the "Compile PDF" option, the conversion occurs successfully.
As a sample I leave:
- Calling the R script from Index.Rmd
#chunk
options(tinytex.engine_args = '-shell-escape') # Minted indent
library(ggplot2)
library(kableExtra)
options(kableExtra.html.bsTable = T)
library(gridExtra)
# Controlador para ejecutar archivos .Rnw que generar los talleres en PDF Latex
source("Talleres/informes.R", local = knitr::knit_global())
- Reports.R file code
talleres = list.files(path = "Talleres")
talleres = talleres[grepl(".Rnw", talleres)]
lapply(as.list(talleres), function(taller){
salida = paste("Talleres/",
gsub(pattern = ".Rnw", replacement = "", x = taller),
".tex", sep = "")
taller = paste("Talleres/", taller, sep = "")
library(knitr)
knitr::knit2pdf(input = taller, output = salida)
})
- bug photo
- Photo of the expected result
En particular, traté de consultar la documentación de Bookdown pero dado mis conocimientos no pude dar con la solución (si es que está en dicha documentación).
I'm sorry for any errors this first publication may have.