使用download.file同时下载

时间:2015-06-25 01:36:35

标签: r download

自版本3.2.1起,official R文档表明支持同时下载。以下是帮助文件中引用的文字:

对方法“libcurl”的支持是可选的:使用功能(“libcurl”)来查看构建是否支持它。它提供对https://和ftps:// URL的(非阻塞)访问。支持同时下载,因此url和destfile可以是长度大于1的字符向量。对于单个URL和quiet = FALSE,交互式使用中会显示进度条。

但是当我尝试从两个不同的网站下载两个文件时,它只下载了一个:

url_list<-c("http://cran.r-project.org/doc/manuals/r-patched/R-exts.html","http://cran.r-project.org/doc/manuals/r-patched/NEWS.pdf")
dest_list<-c("test1.html","test2.pdf")
download.file(url_list,dest_list)

trying URL 'http://cran.r-project.org/doc/manuals/r-patched/R-exts.html'
Content type 'text/html' length 874175 bytes (853 KB)
downloaded 853 KB

Warning messages:
1: In download.file(url_list, dest_list) :
  only first element of 'url' argument used
2: In download.file(url_list, dest_list) :
  only first element of 'destfile' argument used

然后,我看到我错过了使用参数method="libcurl"

download.file(url_list,dest_list,method="libcurl"). 

在RStudio中运行此命令后:R Studio会发出致命警告并且R会话中止。使用R for Windows GUI,会出现以下警告(然后关闭):

用于Windows GUI前端的

R已停止工作。 “问题导致程序无法正常工作。如果解决方案可用,Windows将关闭程序并通知您。”

我使用的是Windows 8.0。我还运行了capabilities("libcurl"),它提供了以下输出。

libcurl 
   TRUE

1 个答案:

答案 0 :(得分:4)

根据@thelatemail的评论:设置quiet=TRUE会得到所需的结果(这意味着它取决于进度条):

download.file(url_list,dest_list,method="libcurl",quiet=TRUE)