Installing Pandoc from R (on Windows) – using the {installr} package

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!

pandoc_diagram

17 thoughts on “Installing Pandoc from R (on Windows) – using the {installr} package”

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

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

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

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

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

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

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

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

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

Leave a Reply to Rolf FredheimCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.