0

I'm trying to create a bat file that will, among other things, create a .pdf report using RStudio at the end of it, I'm currently using this line

R -e "base.path <- 'C:\\temp'; rmarkdown::render('c:\\temp\\report\\report.Rmd')" > C:\temp\log_r.txt 2> C:\temp\log_r_err.txt

Now, if I run this line through the command prompt, it works like a charm, but when I put this line inside a .bat file, I get the error in the title.

I already checked the environment variables, to make sure that RStudio is in the path, but let me know if I'm forgetting something else here.

Edit: the other answers that I found here were unable to solve my problem.

Diogo Salazar
  • 39
  • 2
  • 9
  • You say RStudio is in the path, but this is irrelevant. Is R in your path? – Andrie May 20 '16 at 22:16
  • 1
    You want to execute an R script in batch mode. Instead of using `R`, try calling the script with `Rscript`, preferably by including the entire path to Rscript, e.g., "C:\Program Files\R\R-3.3.0\bin\x64\Rscript.exe". – RHertel May 21 '16 at 05:06
  • 1
    See, e.g., these threads ([1](http://stackoverflow.com/q/3506007/4770166) , [2](http://stackoverflow.com/questions/19724875/how-to-create-shortcut-to-rscript-on-windows-7)) for more information. – RHertel May 21 '16 at 05:57
  • @RHertel, sorry, R is in the path as well. I did try passing the whole path to Rscript.exe but then I got a new error: Error: pandoc version 1.12.3 or higher is required and was not found. – Diogo Salazar May 24 '16 at 15:29
  • Congratulations, the error message means that you have succeeded in running the script with `Rscript`! The error that you are describing does not seem to be an issue that is related to the call through a command prompt. Rather, it seems to be related to `knitr` and some settings of environment variables. See eg. [here](http://stackoverflow.com/questions/28432607/pandoc-version-1-12-3-or-higher-is-required-and-was-not-found-r-shiny) and [here](http://r.789695.n4.nabble.com/Error-pandoc-version-1-12-3-or-higher-is-required-and-was-not-found-td4712689.html). Hope this helps. – RHertel May 24 '16 at 15:41
  • Well, it seems to be leading somewhere. I followed the instructions on setting the enviroment variable at the start of the script and now I get this: `pandoc.exe: pdflatex not found. pdflatex is needed for pdf output. Error: pandoc document conversion failed with error 41` – Diogo Salazar May 24 '16 at 17:25
  • I did try putting the pdflatex.exe in the enviroment variables but I still got the same error – Diogo Salazar May 24 '16 at 17:27

1 Answers1

0

In the end I was able to solve it, after the last message showed up I kept track of every possible path environment variable and I got this final list:

[PATH]\R\R-3.3.0\bin\x64
[PATH]\RStudio\bin\x64
[PATH]\RStudio\bin\pandoc
[PATH]\Rtools\bin
[PATH]\texlive\2015\bin\win32

Textlive can be replaced by any other LaTeX software.

Diogo Salazar
  • 39
  • 2
  • 9