It’s better not to use “for loop, while loop” in R, I want to downlod a url from web with two methods:
1.Using a for loop
url1="http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html"
url2="http://en.wikipedia.org/wiki/Xz"
url=c(url1,url2)
dw=c("test1","test2")
for (i in 1:2){download.file(url[i],destfile=dw[i])}
How can I change “for loop” method into “apply” method?
2.Using RCurl
require(RCurl)
urls = c("http://stat.ethz.ch/R-manual/R-devel/library/base/html/connections.html", "http://en.wikipedia.org/wiki/Xz")
txt = getURIAsynchronous(urls)
How about the urls contain thousands of web address? If urls contain 10000 web addresses, There Is Not Enough Memory or Disk Space to …
You can use
mapplyA similar approach should work for
RCurl, although I cannot test this due to firewall / proxy restrictions