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 *.utf8.md
  3. pandoc to *.tex (pandoc mwe.utf8.md --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: |
  \usepackage{epstopdf}
  \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{sips -s format png #1 --out \OutputFile}
  \PrependGraphicsExtensions{.tif, .tiff}
output: 
  pdf_document:
    pandoc_args: "--pdf-engine-opt=-shell-escape"
---

![](image.tif)

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 mwe.md -o mwe.pdf in the terminal returns the correct PDF. Alternatively, running $ pandoc mwe.md -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: https://upload.wikimedia.org/wikipedia/commons/6/6a/Chi_Recombination_Model_for_Wikipedia.tif

I too have now run into this problem, where I would like to include some TIFF files and have them auto-converted to PNG files. When I try typesetting the provided 'mwe.Rmd' from within the latest version of RStudio on a MacBook Air, it dies:

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

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

Note that I changed the line to:

    pandoc_args: "--latex-engine-opt=-shell-escape"

and it looks like it is generating a pandoc command that contains the requested 'latex-engine-opt' option:

/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc +RTS -K512m -RTS mwe.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output mwe.tex --template /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --latex-engine-opt=-shell-escape --variable 'geometry:margin=1in' 

But the mwe.log indicates that the 'sips' command was not executed, and so the needed png file was not created:

runsystem(sips -s format png image.tif --out image-tif-converted-to.png)...disabled (restricted).

Would be nice to have a solution to this.

Thank you.