0

I am trying to call water level data from NOAA using the rnoaa library. Water level data is restricted to 31 days and I need data across multiple months. I found the following 'while' loop when looking for similar questions: Looking for a solution in R to loop through a date range to get climate data from NOAA API

When I run the code below, I get the following error:

Error in if (req_dur > maxdur) { : missing value where TRUE/FALSE needed

beginDate <- as.Date('2022-01-01')
endDate <- as.Date('2022-05-01')

date <- beginDate

while (date <= endDate){
  water_level <- coops_search(
  station_name = 8418150, 
  begin_date = date, 
  end_date = date + 1, 
  product = 'water_level', 
  datum = 'MHW', 
  units = 'metric', 
  time_zone = 'lst')
  
  date <- date + 1
}

I've tried changing the beginDate and endDate parameters to the following and still get the same error:

beginDate<- as.Date("20220101",format = "%Y%m%d")
  endDate <- as.Date("20220501",format = "%Y%m%d" )

Any suggestions? Thank you!

Max
  • 23
  • 3

0 Answers0