0

NOAA has a request limit of 1000. I am trying to get 1 year worth of climate data of (PRCP, TMAX, TMIN which is over 1000) and put into a data frame.

I have tried a while loop to go through the date range one day at a time

start <- as.Date("2013-07-01",format = "%Y%m%d")
end <- as.Date("2014-06-30",format = "%Y%m%d")

theDate <- start

while (theDate <= end)
{
  df <- ncdc(
   datasetid = 'GHCND',
   stationid = 'GHCND:ASN00009225',
   token = "token code", 
   startdate = theDate,
   enddate = theDate +1,
   limit = 1000
  )$data

  theDate <- theDate + 1
}  

I get the following error message

Error in while (theDate <= end) { : missing value where TRUE/FALSE needed
sckott
  • 5,755
  • 2
  • 26
  • 42
Spooked
  • 586
  • 1
  • 4
  • 16

1 Answers1

0

You got the dates wrong. Its looking for "-"

try with this

start <- as.Date("20130701",format = "%Y%m%d")
end <- as.Date("20140630",format = "%Y%m%d" )
MatthewR
  • 2,660
  • 5
  • 26
  • 37
  • thanks, however, I now get a new error "Error: (500) - An error occurred while servicing your request.Error: (500)" – Spooked May 17 '19 at 10:54
  • hmm, it works for me, which packages do you have loaded? – MatthewR May 17 '19 at 11:44
  • I have a few as its part of a larger project but I have rnoaa, tidyverse, dplyr,ggplot2,ludridate,fitdistrplus,mass,broom,visreg,mosiac. R version 3.5.1 – Spooked May 17 '19 at 13:50
  • 1
    `rnoaa` maintainer here - you do need to fix your dates, to either do as this answer does with the dashes, or just like `as.Date("2019-05-20")` without the format param - you can also just pass in dates as character class. I just pushed a fix for `ncdc()` https://github.com/ropensci/rnoaa/issues/307 as it didn't handle date classes, but it should, reinstall like `remotes::install_github("ropensci/rnoaa")`, then try again – sckott May 20 '19 at 17:16