4

I'd like to generate html file via script below which is a part of complex source code but I don't want to install RStudio on users machine.

I'm using pandoc available at: pandoc from github and the reference for path to this pandoc file is used in Sys.setenv: "C:/Users/username/AppData/Local/Pandoc".

If I use RSTUDIO_PANDOC in Sys.setenv command, everything works fine in my script below but I'm just confused if RSTUDIO_PANDOC in Sys.setenv command uses default RStudio pandoc file which I don't wanna use. Is there any replacement by RSTUDIO_PANDOC to be sure I don't need RStudio to be installed on user's machine and I can refer only to pandoc file what I downloaded from the link above.

Sys.setenv(RSTUDIO_PANDOC="C:/Users/username/AppData/Local/Pandoc")
setwd("C:/Users/username/interactiveKnitr") # set path to .Rmd file
knit('knit.Rmd') # creates md file
render('knit.Rmd') # creates html file

Thank you very much for any of your explanation and help on this. I'm very new in this area.

SmithiM
  • 231
  • 3
  • 10

1 Answers1

2

You can use the package pander form within R. Despite of that I usually prefer to install pandoc myself and to use a system call if I need to run everything form R.

knit (input = "file.Rmd", output = "file.md")
system ("pandoc file.md")

Then is easier to tune pandoc parameters and you make sure to run the version you have installed. It makes also things easier if you want to create tex or pdf version of the document.

dmontaner
  • 2,076
  • 1
  • 14
  • 17
  • And do you still need to use Sys.setenv(RSTUDIO_PANDOC="C:/Users/username/AppData/Local/Pandoc")? – SmithiM Mar 11 '16 at 10:10
  • I do not think so. Indeed I use it outside Rstudio (also form R studio). The call to `knitr` depends just on `knitr` parameters and the call to system should not be affected by Rstudio parameters... but I guess you can make sure of the pandoc version you are using setting the full path in your system call `system ("C:/User..../pandoc file.md")` – dmontaner Mar 11 '16 at 10:17
  • I have no idea how can I test this, because I don't want to uninstall RStudio from my pc :-) – SmithiM Mar 11 '16 at 10:30
  • Run R outside Rstudio. If you are in Windows you can use the standard R interface or use the batch mode form the DOS shell. See here http://www.statmethods.net/interface/batch.html. Writhe your file.Rmd with any editor (Rstudio for instance) save it just as it is (a text file) and then close Rstudio and open R without it. Remember to load the knitr package. – dmontaner Mar 11 '16 at 10:39