R Markdown PDF generator in portable version


#1

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

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


#3

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


#4

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:


#5

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).


#6

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.


#7

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))
}

#8

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


#9

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


#10

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:


#11

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


#12

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.