Commit 460fe70f authored by Laura A DeCicco's avatar Laura A DeCicco Committed by GitHub
Browse files

Merge pull request #336 from wdwatkins/master

NGWMN tests back in
parents 28e2ddb3 cee19580
......@@ -104,7 +104,7 @@ getQuerySummary <- function(url){
retryGetOrPost <- function(url, ...) {
resp <- NULL
if (nchar(url) < 2048) {
if (nchar(url) < 2048 || grepl(pattern = "ngwmn", x = url)) {
resp <- RETRY("GET", url, ..., user_agent(default_ua()))
} else {
split <- strsplit(url, "?", fixed=TRUE)
......
#' import data from the National Groundwater Monitoring Network \url{http://cida.usgs.gov/ngwmn/}.
#'
#' Only water level data is currently available through the web service.
#' Only water level data and site locations and names are currently available through the web service.
#' @param asDateTime logical if \code{TRUE}, will convert times to POSIXct format. Currently defaults to
#' \code{FALSE} since time zone information is not included.
#' @param tz character to set timezone attribute of datetime. Default is an empty quote, which converts the
......@@ -93,8 +93,8 @@ readNGWMNdata <- function(..., asDateTime = TRUE, tz = ""){
#' Retrieve groundwater levels from the National Ground Water Monitoring Network \url{http://cida.usgs.gov/ngwmn/}.
#'
#' @param featureID character Vector of feature IDs in the formatted with agency code and site number
#' separated by a period, e.g. \code{USGS.404159100494601}.
#' @param featureID character Vector of feature IDs formatted with agency code and site number
#' separated by a period or semicolon, e.g. \code{USGS.404159100494601}.
#' @param asDateTime logical Should dates and times be converted to date/time objects,
#' or returned as character? Defaults to \code{TRUE}. Must be set to \code{FALSE} if a site
#' contains non-standard dates.
......@@ -108,12 +108,12 @@ readNGWMNdata <- function(..., asDateTime = TRUE, tz = ""){
#' oneSite <- readNGWMNlevels(featureID = site)
#'
#' #multiple sites
#' sites <- c("USGS.272838082142201","USGS.404159100494601", "USGS.401216080362703")
#' sites <- c("USGS:272838082142201","USGS:404159100494601", "USGS:401216080362703")
#' multiSiteData <- readNGWMNlevels(sites)
#'
#' #non-USGS site
#' site <- "MBMG.892195"
#' data <- readNGWMNlevels(featureID = site)
#' data <- readNGWMNlevels(featureID = site, asDateTime = FALSE)
#'
#' #site with no data returns empty data frame
#' noDataSite <- "UTGS.401544112060301"
......@@ -128,8 +128,8 @@ readNGWMNlevels <- function(featureID, asDateTime = TRUE){
#' Retrieve site data from the National Ground Water Monitoring Network \url{http://cida.usgs.gov/ngwmn/}.
#'
#' @param featureID character Vector of feature IDs in the formatted with agency code and site number
#' separated by a period, e.g. \code{USGS.404159100494601}.
#' @param featureID character Vector of feature IDs formatted with agency code and site number
#' separated by a period or semicolon, e.g. \code{USGS.404159100494601}.
#'
#' @export
#' @return A data frame the following columns:
......@@ -146,7 +146,7 @@ readNGWMNlevels <- function(featureID, asDateTime = TRUE){
#' oneSite <- readNGWMNsites(featureID = site)
#'
#' #multiple sites
#' sites <- c("USGS.272838082142201","USGS.404159100494601", "USGS.401216080362703")
#' sites <- c("USGS:272838082142201","USGS:404159100494601", "USGS:401216080362703")
#' multiSiteInfo <- readNGWMNsites(sites)
#'
#' #non-USGS site
......
......@@ -18,7 +18,7 @@ Possible values to provide are "America/New_York","America/Chicago", "America/De
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"}
}
\description{
Only water level data is currently available through the web service.
Only water level data and site locations and names are currently available through the web service.
}
\examples{
\dontrun{
......
......@@ -7,8 +7,8 @@
readNGWMNlevels(featureID, asDateTime = TRUE)
}
\arguments{
\item{featureID}{character Vector of feature IDs in the formatted with agency code and site number
separated by a period, e.g. \code{USGS.404159100494601}.}
\item{featureID}{character Vector of feature IDs formatted with agency code and site number
separated by a period or semicolon, e.g. \code{USGS.404159100494601}.}
\item{asDateTime}{logical Should dates and times be converted to date/time objects,
or returned as character? Defaults to \code{TRUE}. Must be set to \code{FALSE} if a site
......@@ -24,12 +24,12 @@ site <- "USGS.430427089284901"
oneSite <- readNGWMNlevels(featureID = site)
#multiple sites
sites <- c("USGS.272838082142201","USGS.404159100494601", "USGS.401216080362703")
sites <- c("USGS:272838082142201","USGS:404159100494601", "USGS:401216080362703")
multiSiteData <- readNGWMNlevels(sites)
#non-USGS site
site <- "MBMG.892195"
data <- readNGWMNlevels(featureID = site)
data <- readNGWMNlevels(featureID = site, asDateTime = FALSE)
#site with no data returns empty data frame
noDataSite <- "UTGS.401544112060301"
......
......@@ -7,8 +7,8 @@
readNGWMNsites(featureID)
}
\arguments{
\item{featureID}{character Vector of feature IDs in the formatted with agency code and site number
separated by a period, e.g. \code{USGS.404159100494601}.}
\item{featureID}{character Vector of feature IDs formatted with agency code and site number
separated by a period or semicolon, e.g. \code{USGS.404159100494601}.}
}
\value{
A data frame the following columns:
......@@ -29,7 +29,7 @@ site <- "USGS.430427089284901"
oneSite <- readNGWMNsites(featureID = site)
#multiple sites
sites <- c("USGS.272838082142201","USGS.404159100494601", "USGS.401216080362703")
sites <- c("USGS:272838082142201","USGS:404159100494601", "USGS:401216080362703")
multiSiteInfo <- readNGWMNsites(sites)
#non-USGS site
......
......@@ -224,6 +224,7 @@ test_that("state county tests",{
expect_equal(fromIDs, "Bacon County")
})
context("NGWMN")
test_that("NGWMN functions working", {
testthat::skip_on_cran()
noDataSite <- "UTGS.401544112060301"
......@@ -233,8 +234,9 @@ test_that("NGWMN functions working", {
#bounding box and a bigger request
bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -99, 31, 102))
expect_gt(nrow(bboxSites), 0)
# siteInfo <- readNGWMNsites(bboxSites$site[1:100])
siteInfo <- readNGWMNsites(bboxSites$site[1:100])
expect_gt(nrow(siteInfo), 90)
#one site
site <- "USGS.430427089284901"
oneSite <- readNGWMNlevels(featureID = site)
......@@ -251,16 +253,16 @@ test_that("NGWMN functions working", {
expect_true(is.numeric(oneSite$value))
#sites with colons and NAs work
na_colons <- c(NA, bboxSites$site[202], NA, NA)
na_colons <- c(NA, bboxSites$site[200:212], NA, NA)
returnDF <- readNGWMNdata(service = "observation", featureID = na_colons)
expect_is(returnDF, "data.frame")
expect_true(nrow(returnDF) > 1)
expect_true(!is.null(attributes(returnDF)$siteInfo))
# sites <- c("USGS:424427089494701", NA)
# siteInfo <- readNGWMNsites(sites)
# expect_is(siteInfo, "data.frame")
# expect_true(nrow(siteInfo) == 1)
sites <- c("USGS:424427089494701", NA)
siteInfo <- readNGWMNsites(sites)
expect_is(siteInfo, "data.frame")
expect_true(nrow(siteInfo) == 1)
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment