I have the following code (edited):
library(rvest)
library(httr)
folder <- "~/Downloads/DSA2101 Main/data"
dir.create(file.path(folder, "radar_files"))
interval <- seq(0, 55, by = 5)
hour <- c("01", "02", "03")
for (h in hour) {
for (i in interval) {
print(i, length(i))
if (i == 0 | i == 5) {
url <- paste("https://www.nea.gov.sg/docs/default-source/rain-area-240km/dpsri_240km_20220731", h, "0", i, "0000dBR.dpsri.png", sep = "")
} else {
url <- paste("https://www.nea.gov.sg/docs/default-source/rain-area-240km/dpsri_240km_20220731", h, i, "0000dBR.dpsri.png", sep = "")
}
download.file (imgurl, destfile = file.path(folder, "radar_files", basename(url)))
}
}
I am trying to webscrape the 240km radar scans from the aforementioned url in the code and download them into radar_files before zipping the file. Radar_files is a folder I created. However, when I run the code, I get (edited)
trying URL 'NA' Warning: URL 'NA': status was 'Couldn't resolve host name'Error in download.file(imgurl, destfile = file.path(folder, "radar_files", : cannot open URL 'NA'
Where did I go wrong?
Thank you.