Download multiple files using “download.file” function

前端 未结 1 1037
忘了有多久
忘了有多久 2020-12-01 17:27

I am trying to download PDFs from a website using R.

I have a vector of the PDF-URLs (pdfurls) and a vector of destination file names (destinations

相关标签:
1条回答
  • 2020-12-01 18:05

    I think your loop is mostly fine, except you forgot to index the urls and destinations objects.

    Tangentially, I would recommend getting in the habit of using seq_along instead of 1:length() when defining for loops.

    for(i in seq_along(urls)){
        download.file(urls[i], destinations[i], mode="wb")
    }
    

    Or using Map as suggested by @docendodiscimus :

    Map(function(u, d) download.file(u, d, mode="wb"), urls, destinations)
    
    0 讨论(0)
提交回复
热议问题