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

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

(I know that I can do it manually, but when I show it to students - the more steps I can organize in the R-code block), the better)

+7
source share
1 answer

How to simply download the latest installer and start with R:

  • a) Determine the latest version of Pandoc and grab the URL using 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 XML package needed 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 just check the latest version manually if you want:

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

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

     system(t) 
  • Delete the unnecessary file after installation:

     unlink(t) 

PS: sorry, only tested on Windows XP

+11
source

All Articles