Pandoc for generating html file not using RStudio

2019-06-24 14:55发布

问题:

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.

回答1:

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.