hirshg
hirshg

Reputation: 155

Download select files from NOAA in R

I have a list of files I found on the NOAA website with this URL:

https://www.ncei.noaa.gov/data/gsoy/access/

I would like to know how I can load only specific files into R from here.

Upvotes: -1

Views: 337

Answers (1)

Anonymous coward
Anonymous coward

Reputation: 2091

This will be a case where you'll treat it like an FTP.

library(RCurl)
url = "https://www.ncei.noaa.gov/data/gsoy/access/"
filenames = getURL(url, dirlistonly = TRUE)
filenames <- strsplit(filenames, "\r\n")
filenames <- unlist(filenames)

download_filenames <- c("ZI000067781.csv", "ZI000067755.csv") #specify what files you want, do this in whatever way you desire, with a regex, list, etc.


sapply(download_filenames, function(x) {
  download.file(paste(url, filename, sep = ""), paste(getwd(), "/", filename,
                                                                                        sep = ""))
}) #apply a download to your file names

You could also successively read the csv you wanted into a dataframe. Like MrFlick said, not sure what exactly you want.

Upvotes: 0

Related Questions