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
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)