How to make Rstudio use its own version of pandoc?

I am getting sporadic errors from pandoc while trying to knit Rmarkdown files in RStudio. Some files (but not all) consistently return

"Access violation in generated code ...
Error: pandoc documentation failed  with error 11."

In addition to the version of pandoc that is installed along with RStudio, my Windows system also contains a separate installation of Pandoc 2.4 that I use as part of my workflow for a bunch of things outside of R and RStudio. So I really can't (don't want to) uninstall it.

When running at the console inside RStudio, I also see the following:
> Sys.getenv('RSTUDIO_PANDOC')
[1] "C:/Program Files/RStudio/bin/pandoc"

However, the error message that comes while knitting starts the command line with
"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS ...

This command uses the separate 2.4 version of pandoc, even though the (automatic) environment variable points RStudio to its own copy. How do I make RStudio use its own copy so I can at least confirm that the problem is in the pandioc version?

Note: This problem is also harder to debug because the "keep_md: true" setting in the YAML header is being ignored, so I can't test pandoc outside of RStudio on the markdown file.

I really shouldn't answer my own question so quickly. But this may help someone else (and may be useful for RStudio developers as well). This was the YAML header when the file did not work in pandoc:

---
title: 'Whatever'
author: "KRC"
date: "03 November 2018"
output:
  html_document:
    keep_md: true
    toc: true
theme: yeti
highlight: kate
---

And, realizing that it was wrong, I fixe it to look like this:

---
title: 'Whatever'
author: "KRC"
date: "03 November 2018"
output:
  html_document:
    keep_md: true
    toc: true
    theme: yeti
    highlight: kate
---

So, at least for a couple of documents, an apparently unrelated problem (incorrect indenting of other options) was the source of the difficulty.

Of course, I'd still like to know the answer to the question in the title of this topic.

The answer is change your PATH system variable accordingly to your needs. You can do it from your .Renviron file

This topic was automatically closed 21 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.