vscode-R: Cannot render .rmd missing pandoc
Describe the bug
I’m trying to render a simple .Rmd file in VSCode but it keeps telling me
Error: pandoc version 1.12.3 or higher is required and was not found (see the help page ?rmarkdown::pandoc_available).
To Reproduce For testing purposes I tried to render a markdown with only one cell
1+1
with the same result.
When I try to render the same Markdown in RStudio it works without problems. Pandoc is installed under /usr/local/bin/pandoc
and executing pandoc -v
shows the correct version. When I open a radian shell in VSCode and type rmarkdown::pandoc_version()
it also shows the correct version.
The command that VSCode executes it
rmarkdown::render('[path to file]/Chap04.Rmd', encoding = 'UTF-8')
Expected behavior VSCode should render the markdown just as RStudio does.
Environment (please complete the following information):
- OS: macOS
- VSCode Version: 1.64.0
- R Version: 4.1.2
- vscode-R version: 2.3.6
- pandoc version: 2.17.1.1
Additional context
I tried the various other solutions to this problem such as setting the RSTUDIO_PANDOC
variable but without any luck.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 18 (4 by maintainers)
Commenting to lend a hand to others who might encounter a similar issue with this in the future.
TLDR
Custom
Rmd
yaml
commands overwrite all other; to get knitting working inVSCode
with a custom command and theRStudio
version ofpandoc
modify your command as such:Explanation
I am using
VSCode
for myR
work and wanted toknit
a document. First I ran into the issue mentioned here thatpandoc
cannot be found so I installedpandoc
viaconda
. This worked perfectly and I could now click theknit
button inVSCode
andknit
my document.I later noticed there were differences in the products from
RStudio
knits
toVSCode
knits
. For example footnotes were not rendering.I would write in
Rmd
:The result in
RStudio
knit would be:However in
VSCode
result would be:There were other differences as well this is why I investigated. I noticed my
knit
commands being executed were:These were indeed using different
pandoc
versions/executables.I uninstalled
conda
pandoc
and tried running again; but failure asVSCode
knit
cannot findpandoc
.Nothing worked, even setting
env
variables etc and even setting the knit command as stated in this thread in theVSCode
settings.I noticed that the command being executed was actually the custom command I set in my
Rmd
yaml
; which overwrites any other and modified it to this:One simple solution is to copy the pandoc binary bundled in RStudio to /usr/local/bin.
In short:
file.copy(rmarkdown::pandoc_exec(), "/usr/local/bin/pandoc", overwrite = TRUE)
Ok, few more pieces of info specific to VS Code:
rmarkdown::find_pandoc()
fails to find pandoc. If I exit R, then activate the conda environment in which I have R installed, then boot R again, then pandoc is found as above. Thus, there may be some sort of issue with having R in a conda environment? I have set the R path to that in the conda environment, but do I need to do something else to get VS Code to automatically correctly use this version of R?R > Rmarkdown > Knit: Use Background Process
is unselected. Probably whatever background process is spun up is using the default R environment that cannot find pandoc? Any way to figure out which R this is?Use Background Process
setting?Thanks that solved the issue! If anybody else has this issue: Set Settings > R > Rmarkdown > Knit: Command to
Sys.setenv(RSTUDIO_PANDOC="--path to pandoc"); rmarkdown::render
I’m still a bit confused because I was able to knit my rmarkdowns without issues before and am not sure what caused it to crash but it is resolved. Thanks to all!I’m wondering if this is a
.bash_profile
vs.bashrc
issue ? As in I’m wondering if @timo-berg has defined their pandoc PATH as part of the.bash_profile
but that its not going loaded in vscode-r’s call to R / rmarkdown?Doing some googling it looks like rmarkdown looks for the value of
RSTUDIO_PANDOC
to find pandoc if its not on your PATH. A simple solution in theory then would be to addin a
.Renviron
file in the root your project (or in the globalRenviron
file if you have root access).(source: https://stackoverflow.com/questions/28432607/pandoc-version-1-12-3-or-higher-is-required-and-was-not-found-r-shiny/29710643#29710643)
I am running R using vscode in a conda environment of a remote server.
I notice that the
PATH
in the vscode interactive R terminal does not include the necessary environment path. I came up with this solution. Here is mysettings.json
file.Installing Pandoc using homebrew solved my problem.
brew install pandoc