From b79e12d4254e103e6307f896585a7cf7f834daa7 Mon Sep 17 00:00:00 2001 From: Laura DeCicco <ldecicco@usgs.gov> Date: Tue, 22 Jan 2013 16:06:21 -0600 Subject: [PATCH] Added a logical argument to decide whether or not to convert from cfs to cms. --- R/getDVData.r | 8 ++++++-- R/retrieveNWISData.r | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/R/getDVData.r b/R/getDVData.r index ff8ffd4a..2bc1677c 100644 --- a/R/getDVData.r +++ b/R/getDVData.r @@ -9,6 +9,8 @@ #' @param StartDate string starting date for data retrieval in the form YYYY-MM-DD. #' @param EndDate string ending date for data retrieval in the form YYYY-MM-DD. #' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks. +#' @param convert logical Option to include a conversion from cfs to cms (35.314667). The default is TRUE, +#' which is appropriate for using NWIS data in the EGRET package. Set this to FALSE to not include the conversion. #' @keywords data import USGS WRTDS #' @export #' @return Daily dataframe @@ -16,10 +18,12 @@ #' @examples #' # These examples require an internet connection to run #' Daily <- getDVData('01594440','00060', '1985-01-01', '1985-03-31', interactive=FALSE) -getDVData <- function (siteNumber,ParameterCd,StartDate,EndDate,interactive=TRUE){ +getDVData <- function (siteNumber,ParameterCd,StartDate,EndDate,interactive=TRUE,convert=TRUE){ data <- retrieveNWISData(siteNumber,ParameterCd,StartDate,EndDate,interactive=interactive) + # need to setup conversion factor because the NWIS data are in cfs but we store in cms - qConvert<-35.314667 + names(data) <- c('agency', 'site', 'dateTime', 'value', 'code') # do a merge instead? + qConvert<- ifelse(convert,35.314667,1) localDaily <- populateDaily(data,qConvert,interactive=interactive) return (localDaily) } \ No newline at end of file diff --git a/R/retrieveNWISData.r b/R/retrieveNWISData.r index ac99bf09..8e3ca945 100644 --- a/R/retrieveNWISData.r +++ b/R/retrieveNWISData.r @@ -64,15 +64,15 @@ retrieveNWISData <- function (siteNumber,ParameterCd,StartDate,EndDate,StatCd="0 if(class(ret.val) == "try-error") ret.val <- x } - else if(regexpr('n$', Typ) > 0) # Must be numeric...be careful of ice - ret.val <- as.numeric(x) +# else if(regexpr('n$', Typ) > 0) # Must be numeric...be careful of ice +# ret.val <- as.numeric(x) else # Must be character ret.val <- x return(ret.val)}) retval <- as.data.frame(retval, stringsAsFactors=FALSE) - colNames <- names(retval) +# colNames <- names(retval) + - names(retval) <- c('agency', 'site', 'dateTime', 'value', 'code') # do a merge instead? return (retval) } \ No newline at end of file -- GitLab