R Markdown PDF generator in portable version

Hi everyone,

I'm trying to create a folder with : R + rmarkdown + PANDOC + MiKteX, which I could move from computer to computer and allows the user to generate a PDF from a standard Rmd file with parameters. I'm on Windows.

So far I have successfully downloaded "R-Portable" and ran an R script from it. I've also download pandoc but I don't know how to specify to R / rmarkdown in which folder it should go to access "pandoc.exe". Any idea on this point ?
I've seen the global environment variable "RSTUDIO_PANDOC" but I don't have (and don't want) RStudio in this special scenario.

Then I will probably need the same info for MiKteX : how to specify to R / rmarkdown where to find the proper version of MiKteX ?

Any advice is welcome and if you have ever encountered the same kind of situation, I would be happy to have your input. Thanks ! :slight_smile:

Best regards.

2 Likes

Have you looked at docker containers?

http://ropenscilabs.github.io/r-docker-tutorial/

http://seankross.com/2017/09/17/Enough-Docker-to-be-Dangerous.html

Actually, @mara made a list of R + Docker links :slightly_smiling_face:

Hi,

Thanks for your quick reply !

I know a little bit of docker but I think it needs to be installed on the computer before it can run, right ?

The thing I try to achieve is basically to have a folder with a portable version of : R / Pandoc / MikTeX / rmarkdown, a Rmd file, a R script and a batch file (for Windows). Then I want to be able to send this ZIP folder by email and the person just have to unzip it and run the batch file to get his PDF : without having to install anything on his computer.

I'm not sure if this could be done with Docker...

Anyway, beside of this specific problem, I'm curious about how to specify specific path in R, especially the one to pandoc here.

Any other idea ?

Thanks @prosoitos ! :slight_smile:

This is certainly possible, but I'm afraid I'm not able to type out a full answer (due to limited time). Basically they all boil down to one thing: the PATH variable. As long as you set the PATH variable correctly in your batch file, it should be able to compile the PDF. The PATH variable should contain the paths to the executables of R (R.exe or Rscript.exe), Pandoc (pandoc.exe), and MiKTeX (pdflatex.exe, etc).

Thanks for your answer @yihui ! :slight_smile:

It's the conclusion I reached after a long row of research on the internet. I think I have to specify a local/temporary PATH for pandoc and MikTeX. To do so in R, I've seen the : Sys.setenv() function, but cant' figure out what is the proper syntax. Any hint on this point ?

Thank you !

Best regards.

A brief answer to give you an idea:

add_path = function(path) {
  s = .Platform$path.sep
  paths = c(path, unlist(strsplit(Sys.getenv('PATH'), s))
  Sys.setenv(PATH = paste(paths, collapse = s))
}
4 Likes

Thank you very much @yihui, it worked like a charm ! :wink:

1 Like

If your question's been answered, would you mind choosing a solution? (see FAQ below for how) It makes it a bit easier to visually navigate the site and see which questions still need help.

Thanks

1 Like

Thanks for the hint @mara, I looked for it but didn't find a way to mark it's solved, I dont' why because now it seems obvious :laughing:

1 Like

Yeah, it's not obvious if you don't know where to look β€” that's why I made that little pictorial! :+1:

1 Like

Another solution could be to create conda environment with R + rmarkdown + PANDOC + MiKteX. You and your collaborator need to install also miniconda (easy). Then you need only to add environment.yml text file to your Rmd file and installation of all dependencies can be automated.

Hi @ADeschamps I have the same escenario, I want to distribute my R App, so I've build it with R portable. My App generate some .md files from the R script, and when I run it I get error "pandoc version 1.12.3 or higher is required and was not found".
I've downloaded Pandoc, so, where exactly I should call the pandoc.exe? Where exactly I shoud set PATH variable?
My bundle has this structure:

  • App dir
    • R portable dir
    • PandocExe dir
    • Shinyfiles dir
      • helpfiles dir(.md files)
      • ui.R
      • server.R
    • Run.bat
    • runShinyApp.R

runShinyApp.R has this code:

shiny::runApp('./shiny/', launch.browser=TRUE)

Thanks a lot.

1 Like

Hi @SergioG
could you solve the issue? I am currently facing the same problem.

Hi @SergioG
I have the same problem too, and I donΒ΄t undestand where I have to specify the PATH.

Could any of you figured out how to fix it? Could you please share the specific code and where to put it?

Thanks in advance!!

Cheers

Hi,
I've added a pandoc folder in the project directory:
pandon%20content R%20folder%20structure
In RunShinyApp.R add next line:
Sys.setenv(RSTUDIO_PANDOC = file.path(getwd(), "Pandoc"))

Regards,