diff --git a/R/readNWISunit.r b/R/readNWISunit.r index 3c86e1aa0409df7fea37cd3f41b7d7b838f4d876..89865596a08b81536526537af6c5acd1f35ba1b2 100644 --- a/R/readNWISunit.r +++ b/R/readNWISunit.r @@ -83,13 +83,19 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){ #' Peak flow data from USGS (NWIS) #' -#' Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}. +#' Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}. +#' In some cases, the specific date of the peak data is not know. This function will default to +#' converting the complete dates, dropping rows with incomplete dates. If those incomplete dates are +#' needed, set the `asDateTime` argument to FALSE. No rows will be removed, and no dates will be converted +#' to R Date objects. #' #' @param siteNumbers character USGS site number(or multiple sites). This is usually an 8 digit number. #' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates #' retrieval for the earliest possible record. #' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates #' retrieval for the latest possible record. +#' @param asDateTime logical default to \code{TRUE}. When \code{TRUE}, the peak_dt column is converted +#' to a Date object, and incomplete dates are removed. When \code{FALSE}, no columns are removed, but no dates are converted. #' @return A data frame with the following columns: #' \tabular{lll}{ #' Name \tab Type \tab Description \cr @@ -123,14 +129,22 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){ #' \dontrun{ #' data <- readNWISpeak(siteNumbers) #' } -readNWISpeak <- function (siteNumbers,startDate="",endDate=""){ +readNWISpeak <- function (siteNumbers,startDate="",endDate="", asDateTime=TRUE){ # Doesn't seem to be a peak xml service url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"peak") data <- importRDB1(url, asDateTime=FALSE) - data$peak_dt <- as.Date(data$peak_dt) + if(asDateTime){ + badDates <- which(grepl("[0-9]*-[0-9]*-00",data$peak_dt)) + data <- data[-badDates,] + + if(length(badDates) > 0){ + warning(length(badDates), " rows were thrown out due to incomplete dates") + } + data$peak_dt <- as.Date(data$peak_dt) + } data$gage_ht <- as.numeric(data$gage_ht) siteInfo <- readNWISsite(siteNumbers) diff --git a/man/readNWISpeak.Rd b/man/readNWISpeak.Rd index 8e01ddb6439362a5611c5433ecf250adae49d9df..3fbc574dabd47c73cd788bb813400997f599c9bb 100644 --- a/man/readNWISpeak.Rd +++ b/man/readNWISpeak.Rd @@ -4,7 +4,7 @@ \alias{readNWISpeak} \title{Peak flow data from USGS (NWIS)} \usage{ -readNWISpeak(siteNumbers, startDate = "", endDate = "") +readNWISpeak(siteNumbers, startDate = "", endDate = "", asDateTime = TRUE) } \arguments{ \item{siteNumbers}{character USGS site number(or multiple sites). This is usually an 8 digit number.} @@ -14,6 +14,9 @@ retrieval for the earliest possible record.} \item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record.} + +\item{asDateTime}{logical default to \code{TRUE}. When \code{TRUE}, the peak_dt column is converted +to a Date object, and incomplete dates are removed. When \code{FALSE}, no columns are removed, but no dates are converted.} } \value{ A data frame with the following columns: @@ -45,6 +48,10 @@ siteInfo \tab data.frame \tab A data frame containing information on the request } \description{ Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}. +In some cases, the specific date of the peak data is not know. This function will default to +converting the complete dates, dropping rows with incomplete dates. If those incomplete dates are +needed, set the `asDateTime` argument to FALSE. No rows will be removed, and no dates will be converted +to R Date objects. } \examples{ siteNumbers <- c('01594440','040851325')