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):
e.g.:
pdfurls <- c("http://website/name1.pdf", "http://website/name2.pdf")
destinations <- c("C:/username/name1.pdf", "C:/username/name2.pdf")
The code I am using is:
for(i in 1:length(urls)){
download.file(urls, destinations, mode="wb")}
However, when I run the code, R accesses the URL, downloads the first PDF, and repeats downloading the same PDF over and over again.
I have read this post: for loop on R function and was wondering if this has something to do with the function itself or is there a problem with my loop?
The code is similar to the post here: How to download multiple files using loop in R? so I was wondering why it is not working and if there is a better way to download multiple files using R.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…