Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to install pandoc on windows using an R command?

I would like to download and install pandoc on a windows 7 machine, by running a command in R. Is that possible?

(I know I can do this manually, but when I'd show this to students - the more steps I can organize within an R code chunk - the better)

like image 234
Tal Galili Avatar asked Feb 25 '13 16:02

Tal Galili


People also ask

Is pandoc a package in R?

pandoc function is now part of the {installr} package.

Is pandoc installed with RStudio?

The RStudio IDE has bundled a version of Pandoc, so you do not need to install Pandoc by yourself if you are using the RStudio IDE.

Can you pip install pandoc?

Installing via pip If you want pandoc included out of the box, you can utilize our pypandoc_binary package, which are identical to the "pypandoc" package, but with pandoc included.


1 Answers

What about simply downloading the most recent version of the installer and starting that from R:

  1. a) Identify the most recent version of Pandoc and grab the URL with the help of the XML package:

    library(XML)
    page     <- readLines('http://code.google.com/p/pandoc/downloads/list', warn = FALSE)
    pagetree <- htmlTreeParse(page, error=function(...){}, useInternalNodes = TRUE, encoding='UTF-8')
    url      <- xpathSApply(pagetree, '//tr[2]//td[1]//a ', xmlAttrs)[1]
    url      <- paste('http', url, sep = ':')
    

    b) Or apply some regexp magic thanks to @G.Grothendieck instead (no need for the XML package this way):

    page <- readLines('http://code.google.com/p/pandoc/downloads/list', warn = FALSE)
    pat  <- "//pandoc.googlecode.com/files/pandoc-[0-9.]+-setup.exe"
    line <- grep(pat, page, value = TRUE); m <- regexpr(pat, line)
    url  <- paste('http', regmatches(line, m), sep = ':')
    

    c) Or simply check the most recent version manually if you'd feel like that:

    url <- 'http://pandoc.googlecode.com/files/pandoc-1.10.1-setup.exe'
    
  2. Download the file as binary:

    t <- tempfile(fileext = '.exe')
    download.file(url, t, mode = 'wb')
    
  3. And simply run it from R:

    system(t)
    
  4. Remove the needless file after installation:

    unlink(t)
    

PS: sorry, only tested on Windows XP

like image 56
daroczig Avatar answered Nov 23 '22 23:11

daroczig