diff --git a/NAMESPACE b/NAMESPACE index fce5c3d02ffbdefbc623b8f8d98df67c390eed96..d246fb10de47179e45a59bc2be9a5e3b5865e5dd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,7 @@ export(getSampleData) export(getSampleDataFromFile) export(getSiteFileData) export(getUserDaily) +export(getUserInfo) export(getUserSample) export(getWQPData) export(getWQPInfo) diff --git a/R/getMetaData.r b/R/getMetaData.r index ff47453d057eb10ebb53a9c9179316020a45a435..4a01959a1aa4289959eca0064a9618b48af0bbd1 100644 --- a/R/getMetaData.r +++ b/R/getMetaData.r @@ -52,7 +52,7 @@ getMetaData <- function(siteNumber="", parameterCd="",interactive=TRUE){ #' @param siteNumber string USGS site number. This is usually an 8 digit number #' @param parameterCd string USGS parameter code. This is usually an 5 digit number. #' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks. -#' @keywords data import USGS web service WRTDS +#' @keywords data import USGS web service #' @export #' @return INFO dataframe with at least param.nm, param.units, parameShortName, paramNumber #' @examples @@ -85,10 +85,7 @@ getNWISInfo <- function(siteNumber, parameterCd,interactive=TRUE){ #' Import Metadata for Water Quality Portal Data #' -#' Populates INFO data frame for EGRET study. If either station number or parameter code supplied, imports data about a particular USGS site from NWIS web service. -#' This function gets the data from here: \url{http://waterservices.usgs.gov/} -#' A list of parameter codes can be found here: \url{http://nwis.waterdata.usgs.gov/nwis/pmcodes/} -#' If either station number or parameter code is not supplied, the user will be asked to input data. +#' Populates INFO data frame for EGRET study. #' Additionally, the user will be asked for: #' staAbbrev - station abbreviation, will be used in naming output files and for structuring batch jobs #' constitAbbrev - constitute abbreviation @@ -178,7 +175,96 @@ getWQPInfo <- function(siteNumber, parameterCd, interactive=FALSE){ if(interactive){ if(is.na(siteInfo$drainSqKm)){ - cat("No drainage area was listed in the USGS site file for this site.\n") + cat("No drainage area was listed in the WQP site file for this site.\n") + cat("Please enter the drainage area, you can enter it in the units of your choice.\nEnter the area, then enter drainage area code, \n1 is square miles, \n2 is square kilometers, \n3 is acres, \n4 is hectares.\n") + cat("Area(no quotes):\n") + siteInfo$drain.area.va <- readline() + siteInfo$drain.area.va <- as.numeric(siteInfo$drain.area.va) + cat("Unit Code (1-4, no quotes):") + qUnit <- readline() + qUnit <- as.numeric(qUnit) + conversionVector <- c(2.5899881, 1.0, 0.0040468564, 0.01) + siteInfo$drainSqKm <- siteInfo$drain.area.va * conversionVector[qUnit] + } + } + + siteInfo$queryTime <- Sys.time() + siteInfo$paStart <- 10 + siteInfo$paLong <- 12 + + return(siteInfo) +} + + + +#' Import Metadata from User-Generated File +#' +#' Populates INFO data frame for EGRET study. +#' Additionally, the user will be asked for: +#' staAbbrev - station abbreviation, will be used in naming output files and for structuring batch jobs +#' constitAbbrev - constitute abbreviation +#' +#' @param filePath string specifying the path to the file +#' @param fileName string name of file to open +#' @param hasHeader logical true if the first row of data is the column headers +#' @param separator string character that separates data cells +#' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks. +#' @keywords data import USGS web service WRTDS +#' @export +#' @return INFO dataframe with agency, site, dateTime, value, and code columns +#' @examples +#' filePath <- system.file("extdata", package="dataRetrieval") +#' filePath <- paste(filePath,"/",sep="") +#' fileName <- 'infoTest.csv' +#' INFO <- getUserInfo(filePath,fileName, separator=",",interactive=FALSE) +getUserInfo <- function(filePath,fileName,hasHeader=TRUE,separator=",",interactive=FALSE){ + + totalPath <- paste(filePath,fileName,sep=""); + siteInfo <- read.delim( + totalPath, + header = hasHeader, + sep=separator, + colClasses=c('character'), + fill = TRUE, + comment.char="#") + + if(interactive){ + + if (!nzchar(siteInfo$station.nm)){ + cat("No station name was listed. Please enter a station name here(no quotes): \n") + siteInfo$station.nm <- readline() + } + cat("Your site name is", siteInfo$station.nm,",") + cat("but you can modify this to a short name in a style you prefer. \nThis name will be used to label graphs and tables. \n") + cat("If you want the program to use the name given above, just do a carriage return, otherwise enter the preferred short name(no quotes):\n") + siteInfo$shortName <- readline() + if (!nzchar(siteInfo$shortName)) siteInfo$shortName <- siteInfo$station.nm + + if (!nzchar(siteInfo$param.nm)){ + cat("No water quality parameter name was listed.\nPlease enter the name here(no quotes): \n") + siteInfo$param.nm <- readline() + } + + cat("Your water quality data are for '", siteInfo$param.nm, "'.\n") + cat("Typically you will want a shorter name to be used in graphs and tables. The suggested short name is:'", siteInfo$paramShortName, "'.\n") + cat("If you would like to change the short name, enter it here, otherwise just hit enter (no quotes):") + shortNameTemp <- readline() + + if (nchar(shortNameTemp)>0) siteInfo$paramShortName <- shortNameTemp + + if (!nzchar(siteInfo$param.units)){ + cat("No water quality parameter unit was listed.\nPlease enter the units here(no quotes): \n") + siteInfo$param.nm <- readline() + } + cat("The units for the water quality data are: ", siteInfo$param.units, ".\n") + cat("It is helpful to set up a constiuent abbreviation when doing multi-constituent studies, enter a unique id (three or four characters should work something like tn or tp or NO3).\nIt is case sensitive. Even if you don't feel you need an abbreviation you need to enter something (no quotes):\n") + siteInfo$constitAbbrev <- readline() + + cat("It is helpful to set up a station abbreviation when doing multi-site studies, enter a unique id (three or four characters should work).\nIt is case sensitive. Even if you don't feel you need an abbreviation for your site you need to enter something(no quotes):\n") + siteInfo$staAbbrev <- readline() + + if(is.na(siteInfo$drainSqKm)){ + cat("No drainage area was listed as a column named 'drainSqKm'.\n") cat("Please enter the drainage area, you can enter it in the units of your choice.\nEnter the area, then enter drainage area code, \n1 is square miles, \n2 is square kilometers, \n3 is acres, \n4 is hectares.\n") cat("Area(no quotes):\n") siteInfo$drain.area.va <- readline() @@ -189,6 +275,13 @@ getWQPInfo <- function(siteNumber, parameterCd, interactive=FALSE){ conversionVector <- c(2.5899881, 1.0, 0.0040468564, 0.01) siteInfo$drainSqKm <- siteInfo$drain.area.va * conversionVector[qUnit] } + } else { + requiredColumns <- c("drainSqKm", "staAbbrev", "constitAbbrev", + "param.units", "paramShortName","shortName") + if(!all(requiredColumns %in% names(siteInfo))){ + message("The following columns are expected in the EGRET package:\n") + message(requiredColumns[!(requiredColumns %in% names(siteInfo))]) + } } siteInfo$queryTime <- Sys.time() diff --git a/R/getSampleDataFromFile.r b/R/getSampleDataFromFile.r index 89d9074249f05dfe9ab9240ecb814e32d20d0b07..c69d8b6051d523ca3e39e6c2918de10bc8e6581d 100644 --- a/R/getSampleDataFromFile.r +++ b/R/getSampleDataFromFile.r @@ -8,7 +8,6 @@ #' @param separator string character that separates data cells #' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks. #' @keywords data import file -#' @keywords data import USGS WRTDS #' @export #' @return Sample dataframe #' @examples @@ -28,8 +27,7 @@ getSampleDataFromFile <- function (filePath,fileName,hasHeader=TRUE,separator=", #' Import user sample data for EGRET analysis #' -#' Imports data from a user-supplied file, and converts it to a Sample data frame (including summing multiple constituents), appropriate for WRTDS calculations. See -#' section 3.4 of the vignette for more details. +#' Imports data from a user-supplied file, and converts it to a Sample data frame (including summing multiple constituents), appropriate for WRTDS calculations. #' #' @param filePath string specifying the path to the file #' @param fileName string name of file to open @@ -37,7 +35,6 @@ getSampleDataFromFile <- function (filePath,fileName,hasHeader=TRUE,separator=", #' @param separator string character that separates data cells #' @param interactive logical Option for interactive mode. If true, there is user interaction for error handling and data checks. #' @keywords data import file -#' @keywords data import USGS WRTDS #' @seealso \code{\link{compressData}}, \code{\link{populateSampleColumns}} #' @export #' @return Sample dataframe diff --git a/inst/extdata/infoTest.csv b/inst/extdata/infoTest.csv new file mode 100644 index 0000000000000000000000000000000000000000..16ea455a44ada7bbffd4d397cacac35d2c43a527 --- /dev/null +++ b/inst/extdata/infoTest.csv @@ -0,0 +1,2 @@ +drainSqKm, staAbbrev, constitAbbrev, param.units, paramShortName,shortName +50, sampleSite, N, mg/l, Nitrogen, Example Station \ No newline at end of file diff --git a/man/getNWISInfo.Rd b/man/getNWISInfo.Rd index 5003e9510765ec936b8a0f21ce1dbef4e5acd1b3..10f3bdf529b1df517280064a395102ac7903d895 100644 --- a/man/getNWISInfo.Rd +++ b/man/getNWISInfo.Rd @@ -30,7 +30,6 @@ constitAbbrev - constitute abbreviation INFO <- getNWISInfo('05114000','00010') } \keyword{USGS} -\keyword{WRTDS} \keyword{data} \keyword{import} \keyword{service} diff --git a/man/getSampleDataFromFile.Rd b/man/getSampleDataFromFile.Rd index 293ee4bb90c32b28dcbc7cfb031a2c6a1a458b83..ee25a09c5fc0f71e70180d9629d778b83658896b 100644 --- a/man/getSampleDataFromFile.Rd +++ b/man/getSampleDataFromFile.Rd @@ -29,8 +29,6 @@ filePath <- paste(filePath,"/",sep="") fileName <- 'ChoptankRiverNitrate.csv' \dontrun{Sample <- getSampleDataFromFile(filePath,fileName, separator=";",interactive=FALSE)} } -\keyword{USGS} -\keyword{WRTDS} \keyword{data} \keyword{file} \keyword{import} diff --git a/man/getUserInfo.Rd b/man/getUserInfo.Rd new file mode 100644 index 0000000000000000000000000000000000000000..0f56f530fb63f361e3d320c5479a328ea8aecfce --- /dev/null +++ b/man/getUserInfo.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand +\name{getUserInfo} +\alias{getUserInfo} +\title{Import Metadata from User-Generated File} +\usage{ +getUserInfo(filePath, fileName, hasHeader = TRUE, separator = ",", + interactive = FALSE) +} +\arguments{ +\item{filePath}{string specifying the path to the file} + +\item{fileName}{string name of file to open} + +\item{hasHeader}{logical true if the first row of data is the column headers} + +\item{separator}{string character that separates data cells} + +\item{interactive}{logical Option for interactive mode. If true, there is user interaction for error handling and data checks.} +} +\value{ +INFO dataframe with agency, site, dateTime, value, and code columns +} +\description{ +Populates INFO data frame for EGRET study. +Additionally, the user will be asked for: +staAbbrev - station abbreviation, will be used in naming output files and for structuring batch jobs +constitAbbrev - constitute abbreviation +} +\examples{ +filePath <- system.file("extdata", package="dataRetrieval") +filePath <- paste(filePath,"/",sep="") +fileName <- 'infoTest.csv' +INFO <- getUserInfo(filePath,fileName, separator=",",interactive=FALSE) +} +\keyword{USGS} +\keyword{WRTDS} +\keyword{data} +\keyword{import} +\keyword{service} +\keyword{web} + diff --git a/man/getUserSample.Rd b/man/getUserSample.Rd index a15153ebb764bbbac5c5ad07c99ecd2decd8713e..b6b9844172b1facfd8dc8b76691cc2658ade562f 100644 --- a/man/getUserSample.Rd +++ b/man/getUserSample.Rd @@ -21,8 +21,7 @@ getUserSample(filePath, fileName, hasHeader = TRUE, separator = ",", Sample dataframe } \description{ -Imports data from a user-supplied file, and converts it to a Sample data frame (including summing multiple constituents), appropriate for WRTDS calculations. See -section 3.4 of the vignette for more details. +Imports data from a user-supplied file, and converts it to a Sample data frame (including summing multiple constituents), appropriate for WRTDS calculations. } \examples{ filePath <- system.file("extdata", package="dataRetrieval") @@ -33,8 +32,6 @@ Sample <- getUserSample(filePath,fileName, separator=";",interactive=FALSE) \seealso{ \code{\link{compressData}}, \code{\link{populateSampleColumns}} } -\keyword{USGS} -\keyword{WRTDS} \keyword{data} \keyword{file} \keyword{import} diff --git a/man/getWQPInfo.Rd b/man/getWQPInfo.Rd index f400f9c913c755fd95ef6a5d113be23ccba55e2b..362b267ac392cd83aec15a1dae9265cf2a815cbb 100644 --- a/man/getWQPInfo.Rd +++ b/man/getWQPInfo.Rd @@ -16,10 +16,7 @@ getWQPInfo(siteNumber, parameterCd, interactive = FALSE) INFO dataframe with agency, site, dateTime, value, and code columns } \description{ -Populates INFO data frame for EGRET study. If either station number or parameter code supplied, imports data about a particular USGS site from NWIS web service. -This function gets the data from here: \url{http://waterservices.usgs.gov/} -A list of parameter codes can be found here: \url{http://nwis.waterdata.usgs.gov/nwis/pmcodes/} -If either station number or parameter code is not supplied, the user will be asked to input data. +Populates INFO data frame for EGRET study. Additionally, the user will be asked for: staAbbrev - station abbreviation, will be used in naming output files and for structuring batch jobs constitAbbrev - constitute abbreviation