Commit 027efb27 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Merge pull request #76 from ldecicco-USGS/master

Taking out external call on check.
parents 995e4c04 99b64024
......@@ -2,7 +2,7 @@ Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.1.1
Date: 2015-01-02
Date: 2015-02-01
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"),
......
dataRetrieval 2.1.1
===========
* Removed tests that call external web services, server upgrades have been causing false negative results
* Added functionality to readWQPdata to allow R objects as arguments rather than just character strings
* Added parameterCd='all' option for qw calls.
dataRetrieval 2.0.2
===========
* Moved data files (parameterCdFile and pCodeToName) to hidden sysdata.rda
......
......@@ -45,17 +45,17 @@ constructNWISURL <- function(siteNumber,parameterCd="00060",startDate="",endDate
service <- match.arg(service, c("dv","uv","iv","qw","gwlevels","rating","peak","meas"))
if(any(!is.na(parameterCd))){
if(any(!is.na(parameterCd) & parameterCd != "all")){
pcodeCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
if(!pcodeCheck){
badIndex <- which(nchar(parameterCd) != 5 | is.na(suppressWarnings(as.numeric(parameterCd))))
stop("The following pCodes appear mistyped:",paste(parameterCd[badIndex],collapse=","))
} else {
parameterCdCheck <- readNWISpCode(parameterCd)
}
if(length(parameterCd) > 200){
stop("Maximum parameter codes allowed is 200, please adjust data request.")
}
}
multipleSites <- length(siteNumber) > 1
......
......@@ -14,7 +14,9 @@
#' offering <- '00003'
#' property <- '00060'
#' obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
#' \dontrun{
#' rawData <- getWebServiceData(obs_url)
#' }
getWebServiceData <- function(obs_url){
possibleError <- tryCatch({
h <- basicHeaderGatherer()
......
......@@ -49,8 +49,9 @@
#'
#' obs_url <- constructNWISURL(siteNumber,property,
#' startDate,endDate,"dv",format="tsv")
#' data <- importRDB1(obs_url)
#' \dontrun{
#' data <- importRDB1(obs_url)
#'
#' urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
#' startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
#' multiData <- importRDB1(urlMultiPcodes)
......@@ -92,9 +93,7 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
doc <- textConnection(rawData)
}
fileVecChar <- scan(obs_url, what = "", sep = "\n", quiet=TRUE)
pndIndx<-regexpr("^#", fileVecChar)
hdr <- fileVecChar[pndIndx > 0L]
tmp <- read.delim(
doc,
......@@ -106,6 +105,10 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
fill = TRUE,
comment.char="#")
fileVecChar <- scan(obs_url, what = "", sep = "\n", quiet=TRUE)
pndIndx<-regexpr("^#", fileVecChar)
hdr <- fileVecChar[pndIndx > 0L]
dataType <- tmp[1,]
data <- tmp[-1,]
......
......@@ -48,7 +48,7 @@
#' offering <- '00003'
#' property <- '00060'
#' obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
#'
#' \dontrun{
#' data <- importWaterML1(obs_url,TRUE)
#'
#' groundWaterSite <- "431049071324301"
......@@ -62,11 +62,6 @@
#' "2013-11-03","2013-11-03",'uv')
#' unitData <- importWaterML1(unitDataURL,TRUE)
#'
#' filePath <- system.file("extdata", package="dataRetrieval")
#' fileName <- "WaterML1Example.xml"
#' fullPath <- file.path(filePath, fileName)
#' importUserWM1 <- importWaterML1(fullPath,TRUE)
#'
#' # Two sites, two pcodes, one site has two data descriptors:
#' siteNumber <- c('01480015',"04085427")
#' obs_url <- constructNWISURL(siteNumber,c("00060","00010"),startDate,endDate,'dv')
......@@ -84,6 +79,13 @@
#' inactiveAndAcitive <- c("07334200","05212700")
#' inactiveAndAcitive <- constructNWISURL(inactiveAndAcitive, "00060", "2014-01-01", "2014-01-10",'dv')
#' inactiveAndAcitive <- importWaterML1(inactiveAndAcitive)
#'
#' }
#' filePath <- system.file("extdata", package="dataRetrieval")
#' fileName <- "WaterML1Example.xml"
#' fullPath <- file.path(filePath, fileName)
#' imporFile <- importWaterML1(fullPath,TRUE)
#'
importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
if(file.exists(obs_url)){
......
......@@ -25,7 +25,7 @@
#' "featureID=MD-BC-BC-05",
#' "offering=RAW",
#' "observedProperty=WATER",sep="&")
#'
#' \dontrun{
#' dataReturned1 <- importWaterML2(URL)
#' dataReturn2 <- importWaterML2(URL2, TRUE)
#' URLmulti <- paste(baseURL,
......@@ -35,6 +35,7 @@
#' "statCd=00003",
#' "parameterCd=00060",sep="&")
#' dataReturnMulti <- importWaterML2(URLmulti)
#' }
#' filePath <- system.file("extdata", package="dataRetrieval")
#' fileName <- "WaterML2Example.xml"
#' fullPath <- file.path(filePath, fileName)
......
......@@ -5,7 +5,7 @@
#' A list of statistic codes can be found here: \url{http://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table}
#'
#' @param siteNumbers character of USGS site numbers. This is usually an 8 digit number
#' @param parameterCd character of USGS parameter code(s). This is usually an 5 digit number.
#' @param parameterCd character of USGS parameter code(s). This is usually an 5 digit number. Can also be "all".
#' @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
......@@ -56,11 +56,30 @@
#' rawNWISqwData <- readNWISqw(siteNumbers,parameterCd,startDate,endDate)
#' rawNWISqwDataReshaped <- readNWISqw(siteNumbers,parameterCd,
#' startDate,endDate,reshape=TRUE)
#' parameterCd <- "all"
#' rawNWISall <- readNWISqw(siteNumbers,parameterCd,
#' startDate,endDate,reshape=TRUE)
#' }
readNWISqw <- function (siteNumbers,parameterCd,startDate="",endDate="",
expanded=TRUE,reshape=FALSE,tz=""){
url <- constructNWISURL(siteNumbers,parameterCd,startDate,endDate,"qw",expanded=expanded)
if(any(parameterCd == "all")){
siteNumbers <- paste(siteNumbers, collapse=",")
url <- paste0("http://nwis.waterdata.usgs.gov/nwis/qwdata?multiple_site_no=", siteNumbers,
"&sort_key=site_no&group_key=NONE&inventory_output=0",
"&begin_date=", startDate, "&end_date=", endDate,
"&TZoutput=0",
"&radio_parm_cds=all_parm_cds&qw_attributes=0&format=rdb",
"&qw_sample_wide=0&rdb_qw_attributes=expanded&date_format=YYYY-MM-DD",
"&rdb_compression=value&list_of_search_criteria=multiple_site_no")
} else {
url <- constructNWISURL(siteNumbers,
parameterCd,
startDate,
endDate,"qw",expanded=expanded)
}
data <- importRDB1(url,asDateTime=TRUE, qw=TRUE, tz = tz)
originalHeader <- comment(data)
......@@ -68,13 +87,19 @@ readNWISqw <- function (siteNumbers,parameterCd,startDate="",endDate="",
if(reshape & expanded){
columnsToMelt <- c("agency_cd","site_no","sample_dt","sample_tm",
"sample_end_dt","sample_end_tm","sample_start_time_datum_cd","tm_datum_rlbty_cd",
"parm_cd","startDateTime","endDateTime")
"parm_cd","startDateTime","endDateTime","coll_ent_cd", "medium_cd","project_cd",
"aqfr_cd","tu_id","body_part_id", "hyd_cond_cd", "samp_type_cd",
"hyd_event_cd","sample_lab_cm_tx")
columnsToMelt <- columnsToMelt[columnsToMelt %in% names(data)]
longDF <- melt(data, columnsToMelt)
dataWithPcodes <- data[data$parm_cd != "",]
if(sum(data$parm_cd != "") > 0){
warning("Data returned without pCodes, will not be included in reshape")
}
longDF <- melt(dataWithPcodes, columnsToMelt)
wideDF <- dcast(longDF, ... ~ variable + parm_cd )
wideDF[,grep("_va_",names(wideDF))] <- sapply(wideDF[,grep("_va_",names(wideDF))], function(x) as.numeric(x))
groupByPCode <- as.vector(sapply(parameterCd, function(x) grep(x, names(wideDF)) ))
pCodesReturned <- unique(dataWithPcodes$parm_cd)
groupByPCode <- as.vector(sapply(pCodesReturned, function(x) grep(x, names(wideDF)) ))
data <- wideDF[,c(1:length(columnsToMelt)-1,groupByPCode)]
comment(data) <- originalHeader
......
......@@ -60,13 +60,14 @@
#' }
#' @export
#' @examples
#' # These examples require an internet connection to run
#' \dontrun{
#' siteINFO <- readNWISsite('05114000')
#' siteINFOMulti <- readNWISsite(c('05114000','09423350'))
#' }
readNWISsite <- function(siteNumbers){
siteNumber <- paste(siteNumbers,collapse=",")
urlSitefile <- paste("http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=Expanded&sites=",siteNumber,sep = "")
urlSitefile <- paste0("http://waterservices.usgs.gov/nwis/site/?format=rdb&siteOutput=Expanded&sites=",siteNumber)
data <- importRDB1(urlSitefile,asDateTime=FALSE)
......
......@@ -49,9 +49,9 @@
#' parameterCd <- '00060'
#' startDate <- "2014-10-10"
#' endDate <- "2014-10-10"
#' # These examples require an internet connection to run
#' rawData <- readNWISuv(siteNumber,parameterCd,startDate,endDate)
#' \dontrun{
#' rawData <- readNWISuv(siteNumber,parameterCd,startDate,endDate)
#'
#' timeZoneChange <- readNWISuv(c('04024430','04024000'),parameterCd,
#' "2013-11-03","2013-11-03")
#' }
......@@ -104,7 +104,9 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){
#' @export
#' @examples
#' siteNumbers <- c('01594440','040851325')
#' \dontrun{
#' data <- readNWISpeak(siteNumbers)
#' }
readNWISpeak <- function (siteNumbers,startDate="",endDate=""){
# Doesn't seem to be a peak xml service
......@@ -158,8 +160,10 @@ readNWISpeak <- function (siteNumbers,startDate="",endDate=""){
#' @export
#' @examples
#' siteNumber <- '01594440'
#' \dontrun{
#' data <- readNWISrating(siteNumber, "base")
#' attr(data, "RATING")
#' }
readNWISrating <- function (siteNumber,type="base"){
# No rating xml service
......@@ -221,7 +225,9 @@ readNWISrating <- function (siteNumber,type="base"){
#' @export
#' @examples
#' siteNumbers <- c('01594440','040851325')
#' \dontrun{
#' data <- readNWISmeas(siteNumbers)
#' }
readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
# Doesn't seem to be a WaterML1 format option
......@@ -283,10 +289,12 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
#' @export
#' @examples
#' siteNumber <- "434400121275801"
#' \dontrun{
#' data <- readNWISgwl(siteNumber, '','')
#' sites <- c("434400121275801", "375907091432201")
#' data2 <- readNWISgwl(sites, '','')
#' data3 <- readNWISgwl("420125073193001", '','')
#' }
readNWISgwl <- function (siteNumbers,startDate="",endDate=""){
# url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"gwlevels",format="wml1")
......
......@@ -42,9 +42,11 @@
#' siteWithTwo <- '01480015'
#' startDate <- "2012-09-01"
#' endDate <- "2012-10-01"
#' \dontrun{
#' url2 <- constructNWISURL(siteWithTwo, "00060",startDate,endDate,'dv')
#' twoResults <- importWaterML1(url2,TRUE)
#' twoResults <- renameNWISColumns(twoResults)
#' }
renameNWISColumns <- function(rawData, p00010="Wtemp", p00045="Precip",
p00060="Flow", p00065="GH", p00095="SpecCond", p00300="DO",
p00400="pH", p62611="GWL", p63680="Turb", p72019="WLBLS",
......
......@@ -3,8 +3,8 @@
#' \tabular{ll}{
#' Package: \tab dataRetrieval\cr
#' Type: \tab Package\cr
#' Version: \tab 2.0.2\cr
#' Date: \tab 2014-12-15\cr
#' Version: \tab 2.1.1\cr
#' Date: \tab 2015-01-29\cr
#' License: \tab Unlimited for this package, dependencies have more restrictive licensing.\cr
#' Copyright: \tab This software is in the public domain because it contains materials
#' that originally came from the United States Geological Survey, an agency of
......
......@@ -27,7 +27,9 @@
#' @export
#' @import XML
#' @examples
#' \dontrun{
#' siteListPhos <- whatNWISsites(stateCd="OH",parameterCd="00665")
#' }
whatNWISsites <- function(...){
matchReturn <- list(...)
......
......@@ -8,8 +8,8 @@
\tabular{ll}{
Package: \tab dataRetrieval\cr
Type: \tab Package\cr
Version: \tab 2.0.2\cr
Date: \tab 2014-12-15\cr
Version: \tab 2.1.1\cr
Date: \tab 2015-01-29\cr
License: \tab Unlimited for this package, dependencies have more restrictive licensing.\cr
Copyright: \tab This software is in the public domain because it contains materials
that originally came from the United States Geological Survey, an agency of
......
......@@ -23,6 +23,8 @@ endDate <- "2012-10-01"
offering <- '00003'
property <- '00060'
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
\dontrun{
rawData <- getWebServiceData(obs_url)
}
}
......@@ -62,8 +62,9 @@ property <- "00060"
obs_url <- constructNWISURL(siteNumber,property,
startDate,endDate,"dv",format="tsv")
data <- importRDB1(obs_url)
\dontrun{
data <- importRDB1(obs_url)
urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
multiData <- importRDB1(urlMultiPcodes)
......
......@@ -55,7 +55,7 @@ endDate <- "2012-10-01"
offering <- '00003'
property <- '00060'
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
\dontrun{
data <- importWaterML1(obs_url,TRUE)
groundWaterSite <- "431049071324301"
......@@ -69,11 +69,6 @@ unitDataURL <- constructNWISURL(siteNumber,property,
"2013-11-03","2013-11-03",'uv')
unitData <- importWaterML1(unitDataURL,TRUE)
filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML1Example.xml"
fullPath <- file.path(filePath, fileName)
importUserWM1 <- importWaterML1(fullPath,TRUE)
# Two sites, two pcodes, one site has two data descriptors:
siteNumber <- c('01480015',"04085427")
obs_url <- constructNWISURL(siteNumber,c("00060","00010"),startDate,endDate,'dv')
......@@ -91,6 +86,12 @@ inactiveSite <- importWaterML1(inactiveSite)
inactiveAndAcitive <- c("07334200","05212700")
inactiveAndAcitive <- constructNWISURL(inactiveAndAcitive, "00060", "2014-01-01", "2014-01-10",'dv')
inactiveAndAcitive <- importWaterML1(inactiveAndAcitive)
}
filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML1Example.xml"
fullPath <- file.path(filePath, fileName)
imporFile <- importWaterML1(fullPath,TRUE)
}
\seealso{
\code{\link{renameNWISColumns}}
......
......@@ -34,7 +34,7 @@ URL2 <- paste("http://cida.usgs.gov/noreast-sos/simple?request=GetObservation",
"featureID=MD-BC-BC-05",
"offering=RAW",
"observedProperty=WATER",sep="&")
\dontrun{
dataReturned1 <- importWaterML2(URL)
dataReturn2 <- importWaterML2(URL2, TRUE)
URLmulti <- paste(baseURL,
......@@ -44,6 +44,7 @@ URLmulti <- paste(baseURL,
"statCd=00003",
"parameterCd=00060",sep="&")
dataReturnMulti <- importWaterML2(URLmulti)
}
filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML2Example.xml"
fullPath <- file.path(filePath, fileName)
......
......@@ -49,11 +49,13 @@ See \url{http://waterservices.usgs.gov/rest/GW-Levels-Service.html} for more inf
}
\examples{
siteNumber <- "434400121275801"
\dontrun{
data <- readNWISgwl(siteNumber, '','')
sites <- c("434400121275801", "375907091432201")
data2 <- readNWISgwl(sites, '','')
data3 <- readNWISgwl("420125073193001", '','')
}
}
\seealso{
\code{\link{constructNWISURL}}, \code{\link{importRDB1}}
}
......
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