是否可以使用R命令在Windows上安装pandoc?

时间:2023-01-12 15:44:48

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

我想通过在R中运行命令在Windows 7机器上下载并安装pandoc。这可能吗?

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

(我知道我可以手动执行此操作,但是当我向学生展示时 - 我可以在R代码块中组织的步骤越多越好)

1 个解决方案

#1


11  

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

如何简单地下载最新版本的安装程序并从R开始:

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

    a)确定最新版本的Pandoc并在XML包的帮助下获取URL:

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

    b)或者应用一些正则表达式魔术,感谢@ G.Grothendieck(不需要这样的XML包):

    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:

    c)或者,如果您有这样的想法,只需手动检查最新版本:

    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:

    只需从R运行它:

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

    安装后删除不必要的文件:

    unlink(t)
    

PS: sorry, only tested on Windows XP

PS:对不起,只在Windows XP上测试过

#1


11  

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

如何简单地下载最新版本的安装程序并从R开始:

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

    a)确定最新版本的Pandoc并在XML包的帮助下获取URL:

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

    b)或者应用一些正则表达式魔术,感谢@ G.Grothendieck(不需要这样的XML包):

    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:

    c)或者,如果您有这样的想法,只需手动检查最新版本:

    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:

    只需从R运行它:

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

    安装后删除不必要的文件:

    unlink(t)
    

PS: sorry, only tested on Windows XP

PS:对不起,只在Windows XP上测试过