I want to generate PDF reports that take in a parameter (e.g., name) from a list. I am able to generate HTML reports (see command below) but not PDF.
render_fun <- function(intern_name){
rmarkdown::render(input = "./Reports/Report_Interns.Rmd",
output_file = glue::glue("report_{intern_name}"),
params = list(name = intern_name, school = ""))
}
interns_name %>% purrr::walk(render_fun)
Note that the output_file
does not contain an extension (e.g., .pdf). If I do add this extension, the compiler throws an error:
e.g.,
render_fun <- function(intern_name){
rmarkdown::render(input = "./Reports/Report_Interns.Rmd",
output_file = glue::glue("report_{intern_name}.pdf"), # note the .pdf at end
params = list(name = intern_name, school = ""))
}
interns_name %>% purrr::walk(render_fun)
This throws an error:
"C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/pandoc" +RTS -K512m -RTS Report_Interns.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output pandoc8d04ec57a05.pdf --lua-filter "C:\Users\J~1\AppData\Local\R\WIN-LI~1\4.3\bookdown\RMARKD~1\lua\CUSTOM~1.LUA" --lua-filter "C:\Users\J~1\AppData\Local\R\WIN-LI~1\4.3\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\Users\J~1\AppData\Local\R\WIN-LI~1\4.3\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --embed-resources --standalone --wrap preserve --lua-filter "C:/Users/J/AppData/Local/R/win-library/4.3/pagedown/resources/lua/uri-to-fn.lua" --lua-filter "C:/Users/J/AppData/Local/R/win-library/4.3/pagedown/resources/lua/loft.lua" --lua-filter "C:/Users/J/AppData/Local/R/win-library/4.3/pagedown/resources/lua/footnotes.lua" "--mathjax=https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --metadata newpage_html_class="page-break-after" --section-divs --template "C:\Users\J~1\AppData\Local\R\WIN-LI~1\4.3\pagedown\RESOUR~1\html\PAGED~1.HTM" --highlight-style pygments --number-sections --css style.css --include-in-header "C:\Users\J~1\AppData\Local\Temp\RtmpmYEE2S\rmarkdown-str8d079967747.html"
cannot produce pdf output from html4
Error in `map()`:
ℹ In index: 1.
Caused by error:
! pandoc document conversion failed with error 4
I suspect it's because my YAML contains a pagedown library which first generates an HTML and then converts that HTML to PDF.
---
title: "`r params$name`"
author: "`r params$school`"
date: "`r Sys.Date()`"
params:
name: ""
school: "School"
output:
pagedown::html_paged:
css: style.css
knit: pagedown::chrome_print
---
In short, how do I generate PDF reports automatically? If I manually specific name in the YAML, I do get the PDF report so I know that there's nothing wrong with the RMarkdown or pagedown.