Download multiple excel files linked through urls in R

0 votes

I have a list containing hundreds of URLs directly linking to .xlsx files for a download:

list <- c("https://ec.europa.eu/consumers/consumers_safety/safety_products/rapex/alerts/?event=main.weeklyReport.Excel&web_report_id=980", 
          "https://ec.europa.eu/consumers/consumers_safety/safety_products/rapex/alerts/?event=main.weeklyReport.Excel&web_report_id=981", 
          "https://ec.europa.eu/consumers/consumers_safety/safety_products/rapex/alerts/?event=main.weeklyReport.Excel&web_report_id=990")

To download everything in the list, I created a loop:

for (url in list) {
  download.file(url, destfile = "Rapex-Publication.xlsx", mode="wb")
}

However, it only downloads the first file and not the rest. My guess is that the program is overwriting the same destfile. What would I have to do to circumvent this issue?

Sep 22, 2022 in Others by Kithuzzz
• 38,010 points
1,019 views

1 answer to this question.

0 votes

Try something along the lines of:

for (i in 1:length(list)) {
  download.file(list[i], destfile = paste0("Rapex-Publication-", i, ".xlsx"),  mode="wb")
}
answered Sep 23, 2022 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

Crawling through multiple excel files, match and copy data to master file

One application only. It would be quicker ...READ MORE

answered Jan 12, 2023 in Others by narikkadan
• 63,420 points
371 views
0 votes
1 answer

How to open .xlsx files in MS Excel from VS Code?

Hello, to open xlxs files, or files ...READ MORE

answered Feb 17, 2022 in Others by gaurav
• 23,260 points
3,097 views
0 votes
0 answers

Importing Excel files into R, xlsx or xls

Please can someone help me on the ...READ MORE

Jun 13, 2022 in Others by Avinash
• 1,260 points
210 views
0 votes
1 answer
0 votes
1 answer

Excel, How to split cells by comma delimiter into new cells

The Excel manual method: choose Text to Column ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,420 points
627 views
0 votes
1 answer

Conversion of PDF file to Excel in R

I looked at the pdf, and it ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 63,420 points
1,314 views
0 votes
1 answer

Use R to create chart in Excel sheet

Here is a solution utilizing the XLConnect ...READ MORE

answered Nov 10, 2022 in Others by narikkadan
• 63,420 points
675 views
0 votes
1 answer

Write from R into template in excel while preserving formatting

you have the XLConnect package. Read the documentation or the vignette of that ...READ MORE

answered Nov 10, 2022 in Others by narikkadan
• 63,420 points
1,179 views
0 votes
1 answer

Comparing two Excel files in R and returning different titles

Solution: library(tidyverse) dat <- read_xlsx("Book1.xlsx") dat2 <- read_xlsx("Book2.xlsx") book1_output <- anti_join(dat,dat2, ...READ MORE

answered Oct 14, 2022 in Others by narikkadan
• 63,420 points
1,456 views
0 votes
1 answer

Is there any way in python to auto-correct spelling mistake in multiple rows of an excel files of a single column?

Use Spellchecker for doing your stuff: import pandas ...READ MORE

answered Oct 14, 2022 in Others by narikkadan
• 63,420 points
1,594 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP