I need to download a series of Excel files from URL's that all look as follows:
http://example.com/orResultsED.cfm?MODE=exED&ED=01&EventId=31 http://example.com/orResultsED.cfm?MODE=exED&ED=02&EventId=31 ... http://example.com/orResultsED.cfm?MODE=exED&ED=87&EventId=31
I've got some of the building blocks inside the loop, such as:
for(i in 1:87) { url <- paste0("http://example.com/orResultsED.cfm?MODE=exED&ED=", i, "&EventId=31") file <- paste0("Data/myExcel_", i, ".xlsx") if (!file.exists(file)) download.file(url, file) }
My problems:
- I need the
seqto prepend the 0 (I triedsprintfwith no luck) - I also want to import the Excel files, skip the first two rows and append them on after the other (they also have the same columns)
Update
@akrun solution works well. But it turns out not all my Excel files have the same number of columns:
map(files, ~read.xlsx(.x, colNames = FALSE, sheet = 1, startRow = 4, )) %>% bind_rows Error in bind_rows_(x, .id) : Column `X1` can't be converted from numeric to character I think this error actually points to the unequal number of column. I tried adding fill = NA (when testing map_df()), but it didn't help.
Sys.sleep(5)tho. There's no need to download files faster than that.There's also a really good chance one email could end up giving you a ZIP file or even a set of SQL to load these up w/o scraping. But, hey, nice try withexample.com.if (!file.exists(file)) download.file(url, file)from your nuclear animation example! Thanks for chiming in!