rmarkdown::render() in cmd returns pandoc error
Asked Answered
T

1

10

I need to render forms with rmarkdown from a command line

this is where I am:

  • knit button in RStudio works fine
  • function rmarkdown::render(file.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.2\bin\Rscript.exe" -e "rmarkdown::render('C:/file.rmd')

and I get this error:

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

In RStudio I sent

> rmarkdown::pandoc_available()

[1] TRUE
> rmarkdown::pandoc_version()

[1] ‘2.7.3’

What am I missing here?

By the way, I'm on Win10.

Thanks.

Torbert answered 11/8, 2020 at 9:59 Comment(0)
I
9

There might be an issue wit h Pandoc version, obviously. But maybe some library requires that older pandoc version, and the issue comes from you using Rmarkdown from outside Rstudio.

This link has the answer

Go into Rstudio and type

Sys.getenv("RSTUDIO_PANDOC")

Now take the output from the command above and put it here

Sys.setenv(RSTUDIO_PANDOC="OUTPUT FROM ABOVE COMMAND")

Indention answered 11/8, 2020 at 11:11 Comment(1)
Ok so I made a 2 line script : Sys.setenv(RSTUDIO_PANDOC="C:/Program Files/RStudio/bin/pandoc") rmarkdown::render(input = "file.rmd") Now with the CMD I just call this script and it works fine, thanks a lot !Lathy

© 2022 - 2024 — McMap. All rights reserved.