1

So I am migrating from RStudio to Visual Studio Code for my future R projects. I have successfully gotten my github aspect all setup and I am trying to write my code in (.rmd) format so that I can knit it to pdf, html and flex_dashboard outputs. When I have tried to knit the it, I get the following error:

rmarkdown::render("c:\Users\{user}\{folder}\{sub-folder}\{sub-folder}\Co$

Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).>

I found the following solution that once run in the terminal, allows it to knit into a pdf_document successfully.

Code: Sys.setenv(RSTUDIO_PANDOC="--- insert directory here ---")

Reference: pandoc version 1.12.3 or higher is required and was not found (R shiny)

This is great, but everytime I restart VSCode, this setting appears to be reset and I have to run it again. Is there away to set this globally so that I don't have to run it every time I use it? Or is there a better way to do this?

Community
  • 1
  • 1

2 Answers2

2

I had a similar problem before in VScode to render R markdown. Now, I found the solutions to it.

Following the steps below to properly set up the pandoc:

Step 1:

Go to your R Studio and go the console, type the following:

Sys.getenv("RSTUDIO_PANDOC")

If you are using MacOS, you will get the path for "pandoc": "/Applications/RStudio.app/Contents/MacOS/pandoc"

If you are using Windows, you probably will get the path like: "/c/Program Files/RStudio/bin/pandoc/" as mentioned in pandoc version 1.12.3 or higher is required and was not found (R shiny)

Step 2:

Paste the path of "pandoc" and put it into your bash or zsh (depends on what command shell that you are using).

  • On MacOS, I'm using zsh. Therefore, I add the following path into ~/.zshrc:
export RSTUDIO_PANDOC="/Applications/RStudio.app/Contents/MacOS/pandoc"

As for how to edit ~/.zshrc, one way to do this is presented as follows:

step 2.1

nano ~/.zshrc

It will open your .zshrc file and navigate to the bottom of this file, paste the

export RSTUDIO_PANDOC="/Applications/RStudio.app/Contents/MacOS/pandoc". Then, control + X to exit. It will ask about "Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?", then type Y and type return bottom.

step 2.2

source ~/.zshrc

Now, it should work fine in VScode. By checking if it works, you could open your console by typing R to invoke the R environment and type Sys.getenv("RSTUDIO_PANDOC"). If it returns the path of the "pandoc", it would work fine in VScode as well.

Enhao
  • 31
  • 1
  • On a Mac, I think `Sys.getenv(RSTUDIO_PANDOC)` is now located `"/Applications/RStudio.app/Contents/MacOS/quarto/bin")` – Nick Jun 09 '22 at 18:48
2

Adding

"terminal.integrated.env.osx": {
        "RSTUDIO_PANDOC":"/Applications/RStudio.app/Contents/MacOS/pandoc"
    }

into settings.json worked for me. Adding to .zshrc didn't work at all since the System environment wasn't being passed on to the integrated terminal.