Knit in Rstudio passes additional "include-in-header" parameter to pandoc

Hi!

I am working on automatically generating pdf documents with R- I was handed a solution that generates a pdf document when I click Knit in Rstudio, but doesn't when I call rmarkdown::render("New.Rmd").

The error I receive in console: `I was unable to find any missing LaTeX packages from the error log New.log.
! Undefined control sequence.
>{\raggedright \arraybackslash
}p{12em}>{\raggedright \arraybacks...
l.76 ...2em}>{\raggedright\arraybackslash}p{12em}}

Error: LaTeX failed to compile New.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See New.log for more info.`

I have naively chased down the difference in execution to:
Knit in R:
"E:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS New.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output New.tex --lua-filter "E:\Program Files\R\R-4.1.1\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "E:\Program Files\R\R-4.1.1\library\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in" --include-in-header "C:\Users\Brook\AppData\Local\Temp\RtmpA9iAAO\rmarkdown-str1810317f2cc7.html"

and

rmarkdown:render("New.Rmd"):
"E:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS New.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output New.tex --lua-filter "E:\Program Files\R\R-4.1.1\library\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "E:\Program Files\R\R-4.1.1\library\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in"

Where the difference is the missing temporary html file param : --include-in-header "C:\Users\Brook\AppData\Local\Temp\RtmpA9iAAO\rmarkdown-str1810317f2cc7.html"

From my understanding RStudio just calls rmarkdown::render, so I'm wondering if I have missed some magic in my YAML headers:

`output:
pdf_document: default
always_allow_html: yes
header-includes:
- \usepackage{sectsty}
- \allsectionsfont{\color{red}}

options(tinytex.verbose = TRUE)
library(dplyr)
library(knitr)
library(kableExtra)
library(ggplot2)
library(stringr)
library(readr)
library(psych)
knitr::opts_chunk$set(echo = TRUE)

`

Or if there is something else that I am doing incorrectly.

Thanks for your time!
Brook

This... probably won't provide the next reader with resolution, but closing RStudio and reopening magically caused rmarkdown::render("New.Rmd") to pass the --include-in-header "C:\Users\Brook\AppData\Local\Temp\RtmpmetXiU\rmarkdown-str3908193d414d.html" param.

However, immediately calling rmarkdown::render("New.Rmd") from the console again omits the --include-in-header "C:\Users\Brook\AppData\Local\Temp\RtmpmetXiU\rmarkdown-str3908193d414d.html" and then fails to compile. That is:

  1. Restart RStudio
  2. rmarkdown::render("New.Rmd") from the console -> works
  3. rmarkdown::render("New.Rmd") from the console (again) -> fails

Okay, I was able to chase this down: https://github.com/rstudio/rmarkdown/issues/1851

I recommend reading the link above, but in short, to support consecutive calls to render we need to add latex libraries to our YAML configuration. However,

output:
  header-includes:
    - \usepackage{sectsty}
    ...

did not work for me, I used 6.4 Include additional LaTeX packages | R Markdown Cookbook

output:
  pdf_document:
    extra_dependencies:
      sectsty: null
      fancyhdr: null
      ...

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.