The R blogger Rolf Fredheim has recently wrote a great piece called “Reproducible research with R, Knitr, Pandoc and Word“, where he advocates for Pandoc as an essential part of reproducible research workflow in R, in helping to turn documents which are knitted in R into high quality Word for exchanging with our colleagues. It is a great post, with many useful bits of code, and I wanted to supplement it with one missing function: “install.pandoc“.
Update: the install.pandoc function is now part of the {installr} package.
The install.pandoc() function, as the name implies, will recognize the latest version of pandoc, download its installer to your computer, and run it. Making it even simpler for you to experiment with adding pandoc into your workflow.
Here is how to use it:
# installing/loading the package:
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr
# Installing pandoc
install.pandoc()
Note: the code in this function is based on GERGELY DARÓCZI’s coding in his answer on the Q&A forum StackOverflow, and also G. Grothendieck for the non-XML addition to the function. I thank them both!
This is brilliant, thank you!
Thanks Rolf 🙂
What do you think, do you think there is a need for more such functions?
Thanks very good idea! how about mac and linux?
Thanks gokhan,
I would have loved adding mac/linux to the mix. However, my main tool these days is Windows OS, so I can’t develop/debug the relevant code for other OS systems. If you (or someone else) is ready to prepare the code – I’d be happy to add it to the post.
Thank you Tal for sharing that piece of code.
I just wanted to let you know that Tyler Rinker has also published the function in his reports package: https://github.com/trinker/reports
And I would be really happy to extend the function with a Linux solution, but installing an up-to-date version of Pandoc on Linux can be really pain in the @ss as `cabal-install` is needed to compile the binary – not like on Windows.
Hi Gergely,
Regarding Linux – I also have no idea how to do it.
Regarding Tyler – good to know (I found the diff here:
https://github.com/trinker/reports/commit/1e8ee365a3bb941f038a0c82bdb226e371103c7f
)
Again – thank you for your cool good 🙂
With regards,
Tal
I am running R 2.15.3 and tried your code.
> # installing/loading the package:
> if(!require(installr)) { install.packages(“installr”); require(installr)} #load / install+load installr
>
> # Installing pandoc
> install.pandoc()
Error in download.file(exe_URL, destfile = exe_filename, mode = “wb”) :
unsupported URL scheme
As a newbie, I don’t know what this error tells me, except that it seems R cannot find the website (URL) that has Pandoc. What can I do?
Thank you.
Thank you for the bug report Rees.
I see that the guys at pandoc have changed their installer type:
http://code.google.com/p/pandoc/downloads/list
From now on, it appears they no longer offer a .exe file, but a .msi file.
I will fix the function to be able to handle it, and also make a change to the error massage produced.
Thank you for the bug report, I will update here with another comment once I’m done.
o.k., I finished fixing the code and updating it to github.
It will take another month or so before I am allowed to push this version to CRAN again. In the meantime, you (and others) can install the latest version of {installr} by running:
if (!require(‘devtools’)) install.packages(‘devtools’); require(‘devtools’)
install_github(‘installr’, ‘talgalili’)
And then you can run:
require(installr)
install.pandoc()
And it’s now supposed to work (it works for me)
With regards,
Tal
p.s: in the meantime, you can run the function in this way:
install.pandoc(use_regex = FALSE)
And it will download and run the installer with no problem.
I am running R 3.1.2 and tried your code. Unfortunately, it doesn’t work for me :
I got this error message when executing install.pandoc() :
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) : unsupported URL scheme
I saw I’m not the only one with this problem : http://stackoverflow.com/questions/26165008/installing-pandoc-in-windows-7-using-r
Did install.pandoc() become deprecated? What to do to install pandoc from R?
Regards
Hello Didi,
Please run:
setInternet2(TRUE)
And then try again, it should fix the problem.
Tal
Is pandoc available for R version 3.2.2?
Three questions: 1) Is it necessary to establish that you do not already have an installation of Pandoc installed by some other R package before using your installer? 2) If not, will your installer overwrite the existing version with the current one, or install a second copy? 3) Is it possible to make this function so that it can or does set the / LARGEADDRESSAWARE switch during the installation? And a big thanks! for this great service.
I’m using an R package Mapview and a specific part, mapshot, requires pandoc. When I try to install pandoc, I get an error that says it is incompatible with 64bit versions of Windows. Is there another option for me? I’m stuck not being able to use mapshot.