question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot render .rmd missing pandoc

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dereckdemezquitacommented, Oct 3, 2022

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 in VSCode with a custom command and the RStudio version of pandoc modify your command as such:

---
output: github_document
knit: (function(inputFile, encoding) {
        Sys.setenv(RSTUDIO_PANDOC='/Applications/RStudio.app/Contents/MacOS/quarto/bin');
        rmarkdown::render(inputFile,
                        encoding=encoding, 
                        output_file=file.path(dirname(inputFile), "README.md")) })
---

Explanation

I am using VSCode for my R work and wanted to knit a document. First I ran into the issue mentioned here that pandoc cannot be found so I installed pandoc via conda. This worked perfectly and I could now click the knit button in VSCode and knit my document.

I later noticed there were differences in the products from RStudio knits to VSCode knits. For example footnotes were not rendering.

I would write in Rmd:

Some text here and then a footnote^[Some text]

The result in RStudio knit would be:

Some text here and then a footnote[^1]

[^1]: [Some text]

However in VSCode result would be:

Some text here and then a footnote[1]

[1] [Some text]

There were other differences as well this is why I investigated. I noticed my knit commands being executed were:

# studio
/Applications/RStudio.app/Contents/MacOS/quarto/bin/pandoc +RTS -K512m -RTS 03-06-terraform-and-docker.knit.md --to gfm-yaml_metadata_block --from markdown+autolink_bare_uris+tex_math_single_backslash --output ./03-06-terraform-and-docker.md --template /opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/default.md '--webtex=https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;' 
/Applications/RStudio.app/Contents/MacOS/quarto/bin/pandoc +RTS -K512m -RTS ./03-06-terraform-and-docker.md --to html4 --from gfm --output ./03-06-terraform-and-docker.html --standalone --self-contained --highlight-style pygments --template /opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/preview.html --variable 'github-markdown-css:/opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/github.css' --metadata pagetitle=PREVIEW '--webtex=https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;' 

# vscode
/Users/neurox1/Tools/miniconda3/bin/pandoc +RTS -K512m -RTS 03-06-terraform-and-docker.knit.md --to gfm --from markdown+autolink_bare_uris+tex_math_single_backslash --output ./03-06-terraform-and-docker.md --template /opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/default.md '--webtex=https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;' 
/Users/neurox1/Tools/miniconda3/bin/pandoc +RTS -K512m -RTS ./03-06-terraform-and-docker.md --to html4 --from gfm --output ./03-06-terraform-and-docker.html --standalone --self-contained --highlight-style pygments --template /opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/preview.html --variable 'github-markdown-css:/opt/homebrew/lib/R/site-library/rmarkdown/rmarkdown/templates/github_document/resources/github.css' --metadata pagetitle=PREVIEW '--webtex=https://latex.codecogs.com/png.image?%5Cdpi%7B110%7D&space;%5Cbg_white&space;'

These were indeed using different pandoc versions/executables.

I uninstalled conda pandoc and tried running again; but failure as VSCode knit cannot find pandoc.

Nothing worked, even setting env variables etc and even setting the knit command as stated in this thread in the VSCode 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:

---
output: github_document
knit: (function(inputFile, encoding) {
        Sys.setenv(RSTUDIO_PANDOC='/Applications/RStudio.app/Contents/MacOS/quarto/bin');
        rmarkdown::render(inputFile,
                        encoding=encoding, 
                        output_file=file.path(dirname(inputFile), "README.md")) })
---
2reactions
gowerccommented, Feb 12, 2022

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 add

RSTUDIO_PANDOC=/path/to/pandoc

in a .Renviron file in the root your project (or in the global Renviron 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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

rmarkdown::render() in cmd returns pandoc error
rmd ) in a .r file works when run in Rstudio. Then I tried running this command in CMD. c:\Program Files\R\R-4.0.
Read more >
15 Common Problems with rmarkdown (and some solutions)
If you want to practice on fixing broken rmarkdown documents, check out some pathologically broken examples on github at njtierney/rmd-errors.
Read more >
17.3 Render R Markdown with rmarkdown::render() - Bookdown
Rmd file. If Pandoc signals an error, you may start debugging from this .md file. The latter ( envir ) offers a way...
Read more >
Error building R Markdown v2 document
For problem 1, your system needs to have pandoc and pandoc-citeproc installed. How you install those depends on your operating system, but a ......
Read more >
Cannot knit RMD file - Pandoc error - RStudio Community
RMD file It was previously recommended to me via Stack Overflow that I run ... when I call rmarkdown::render in the RStudio R...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found