Render() does not pass -shell-escape arguments from pandoc to pdflatex



I want to render an Rmarkdown file that requires the -shell-escape option in pdflatex or --pdf-engine-opt=-shell-escape option in pandoc. I specified pandoc_args: "--pdf-engine-opt=-shell-escape" in my YAML header, but rmarkdown::render() seems to call programs in this order:

  1. knitr::knit() to *.md
  2. encoding conversion to *
  3. pandoc to *.tex (pandoc --to latex --output mwe.tex ...)
  4. pdflatex to *.pdf (pdflatex mwe.tex)

render() loses my -shell-escape option between steps 3 and 4, and I get an error since pdflatex cannot pass a command to the shell. Is there a way to either: 1) have pandoc output a *.pdf file instead of *.tex, or 2) pass -shell-escape onto pdflatex?

MWE: mwe.Rmd

title: "mwe"
header-includes: |
  \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{sips -s format png #1 --out \OutputFile}
  \PrependGraphicsExtensions{.tif, .tiff}
    pandoc_args: "--pdf-engine-opt=-shell-escape"


Running $ rmarkdown::render("mwe.Rmd", output_file="mwe.pdf") in R console gives the error since pdflatex was not called with -shell-escape:

! Package pdftex.def Error: File `image-tif-converted-to.png' not found.

Error: Failed to compile mwe.tex. See mwe.log for more info.

Running $ knitr::knit("mwe.Rmd") in R console followed by $ pandoc -o mwe.pdf in the terminal returns the correct PDF. Alternatively, running $ pandoc -s -o mwe.tex; pdflatex -shell-escape mwe.tex on the intermediate tex file in the terminal also returns the correct PDF.

TIF image obtained from: