Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simultaneous download using download.file

Tags:

r

download

Since the version 3.2.1, the official R document says that there is support for simultaneous downloads. Following is the quoted text from help file:

Support for method "libcurl" is optional: use capabilities("libcurl") to see if it is supported on your build. It provides (non-blocking) access to https:// and ftps:// URLs. There is support for simultaneous downloads, so url and destfile can be character vectors of the same length greater than one. For a single URL and quiet = FALSE there a progress bar is shown in interactive use.

But when I tried to download two files from two different websites, it downloaded only one:

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

Then, I saw that I missed using an argument method="libcurl"

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

Once I run this command in RStudio: R Studio gives fatal warning and R session gets aborted. With the R for Windows GUI, the following warning occurs (and then shut down):

R for Windows GUI front-end has stopped working. "A problem caused the program to stop working correctly. windows will close the program and notify you if a solution is available.".

I am using Windows 8.0. I also ran capabilities("libcurl") and it gives the following output.

libcurl 
   TRUE
like image 280
user227710 Avatar asked Jun 25 '15 01:06

user227710


1 Answers

As per the comment of @thelatemail: setting quiet=TRUE gives the desired result (which means it is due to the progress bar):

download.file(url_list,dest_list,method="libcurl",quiet=TRUE)
like image 117
user227710 Avatar answered Sep 28 '22 08:09

user227710