如何简单地下载最新版本的安装程序并从R开始:
原文链接:https://www.f2er.com/windows/364671.html> 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)或者应用一些正则表达式魔术,感谢@ 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)或者,如果您有这样的想法,只需手动检查最新版本:
url <- 'http://pandoc.googlecode.com/files/pandoc-1.10.1-setup.exe'
t <- tempfile(fileext = '.exe') download.file(url,t,mode = 'wb')
>只需从R运行它:
system(t)
unlink(t)
PS:对不起,只在Windows XP上测试过