diff --git a/R/readNWISDaily.r b/R/readNWISDaily.r index 311c59b0..05d99d12 100644 --- a/R/readNWISDaily.r +++ b/R/readNWISDaily.r @@ -53,12 +53,27 @@ readNWISDaily <- function (siteNumber,parameterCd="00060", if(nrow(data)>0){ names(data) <- c('agency', 'site', 'dateTime', 'value', 'code') data$dateTime <- as.Date(data$dateTime) + ##################################### + qConvert <- ifelse("00060" == parameterCd, 35.314667, 1) + qConvert<- ifelse(convert,qConvert,1) + + localDaily <- populateDaily(data,qConvert,interactive=interactive) + } else { + localDaily <- data.frame(Date=as.Date(character()), + Q=numeric(), + Julian=numeric(), + Month=numeric(), + Day=numeric(), + DecYear=numeric(), + MonthSeq=numeric(), + Qualifier=character(), + i=integer(), + LogQ=numeric(), + Q7=numeric(), + Q30=numeric(), + stringsAsFactors=FALSE) } - ##################################### - qConvert <- ifelse("00060" == parameterCd, 35.314667, 1) - qConvert<- ifelse(convert,qConvert,1) - - localDaily <- populateDaily(data,qConvert,interactive=interactive) + return (localDaily) } diff --git a/R/readNWISSample.r b/R/readNWISSample.r index 2191b178..6a81f3c3 100644 --- a/R/readNWISSample.r +++ b/R/readNWISSample.r @@ -42,12 +42,29 @@ readNWISSample <- function(siteNumber,parameterCd,startDate="",endDate="",interactive=TRUE){ rawSample <- dataRetrieval::readNWISqw(siteNumber,parameterCd,startDate,endDate, expanded=FALSE) - dataColumns <- grep("p\\d{5}",names(rawSample)) - remarkColumns <- grep("r\\d{5}",names(rawSample)) - totalColumns <-c(grep("sample_dt",names(rawSample)), dataColumns, remarkColumns) - totalColumns <- totalColumns[order(totalColumns)] - compressedData <- compressData(rawSample[,totalColumns], interactive=interactive) - Sample <- populateSampleColumns(compressedData) + if(nrow(rawSample) > 0){ + dataColumns <- grep("p\\d{5}",names(rawSample)) + remarkColumns <- grep("r\\d{5}",names(rawSample)) + totalColumns <-c(grep("sample_dt",names(rawSample)), dataColumns, remarkColumns) + totalColumns <- totalColumns[order(totalColumns)] + compressedData <- compressData(rawSample[,totalColumns], interactive=interactive) + Sample <- populateSampleColumns(compressedData) + } else { + Sample <- data.frame(Date=as.Date(character()), + ConcLow=numeric(), + ConcHigh=numeric(), + Uncen=numeric(), + ConcAve=numeric(), + Julian=numeric(), + Month=numeric(), + Day=numeric(), + DecYear=numeric(), + MonthSeq=numeric(), + SinDY=numeric(), + CosDY=numeric(), + stringsAsFactors=FALSE) + } + return(Sample) } diff --git a/R/readWQPSample.R b/R/readWQPSample.R index db812e7f..35c79e69 100644 --- a/R/readWQPSample.R +++ b/R/readWQPSample.R @@ -40,21 +40,36 @@ readWQPSample <- function(siteNumber,characteristicName,startDate,endDate,intera url <- constructWQPURL(siteNumber,characteristicName,startDate,endDate) retval <- importWQP(url) - - #Check for pcode: - if(all(nchar(characteristicName) == 5)){ - suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(characteristicName)))) - } else { - pCodeLogic <- FALSE - } - if(nrow(retval) > 0){ - data <- processQWData(retval,pCodeLogic) + #Check for pcode: + if(all(nchar(characteristicName) == 5)){ + suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(characteristicName)))) + } else { + pCodeLogic <- FALSE + } + + if(nrow(retval) > 0){ + data <- processQWData(retval,pCodeLogic) + } else { + data <- NULL + } + + compressedData <- compressData(data, interactive=interactive) + Sample <- populateSampleColumns(compressedData) } else { - data <- NULL + Sample <- data.frame(Date=as.Date(character()), + ConcLow=numeric(), + ConcHigh=numeric(), + Uncen=numeric(), + ConcAve=numeric(), + Julian=numeric(), + Month=numeric(), + Day=numeric(), + DecYear=numeric(), + MonthSeq=numeric(), + SinDY=numeric(), + CosDY=numeric(), + stringsAsFactors=FALSE) } - - compressedData <- compressData(data, interactive=interactive) - Sample <- populateSampleColumns(compressedData) return(Sample) }