Skip to content

Commit

Permalink
Merge pull request #178 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
Remove plyr dependency
  • Loading branch information
ldecicco-USGS committed Feb 12, 2016
2 parents bb116e3 + 38f8657 commit 83dc1c6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 32 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
person("David","Lorenz", role=c("aut"),
email = "[email protected]"),
person("Jordan", "Read", role = c("ctb"),
email = "[email protected]"))
email = "[email protected]"),
person("Lindsay","Carr", role=c("ctb"),
email = "[email protected]"))
Description: Collection of functions to help retrieve U.S. Geological Survey
(USGS) and U.S. Environmental Protection Agency (EPA) water quality and
hydrology data from web services. USGS web services are discovered from the
Expand All @@ -29,7 +31,6 @@ Imports:
RCurl,
reshape2,
lubridate,
plyr,
stats,
utils,
dplyr,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ importFrom(XML,xpathSApply)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate_)
importFrom(dplyr,mutate_each_)
importFrom(dplyr,rbind_all)
importFrom(dplyr,select_)
importFrom(lubridate,fast_strptime)
importFrom(lubridate,parse_date_time)
importFrom(plyr,rbind.fill.matrix)
importFrom(readr,col_character)
importFrom(readr,col_number)
importFrom(readr,cols)
Expand Down
1 change: 1 addition & 0 deletions R/AAA.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pkg.env <- new.env()
.onLoad = function(libname, pkgname){
suppressMessages(setAccess('public'))
options(Access.dataRetrieval = NULL)
}
10 changes: 0 additions & 10 deletions R/importWaterML1.r
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){

timeSeries <- xpathApply(doc, "//ns1:timeSeries", namespaces = ns)


if(0 == length(timeSeries)){
df <- data.frame()
attr(df, "queryInfo") <- queryInfo
Expand Down Expand Up @@ -287,16 +286,7 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
datetime <- datetime - tzHours*60*60
}
}

# if(tz != ""){
# attr(datetime, "tzone") <- tz
# df$tz_cd <- rep(tz, nrow(df))
# } else {
# attr(datetime, "tzone") <- "UTC"
# df$tz_cd <- rep("UTC", nrow(df))
# }


} else {

datetime <- as.character(datetime)
Expand Down
25 changes: 6 additions & 19 deletions R/importWaterML2.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @importFrom XML xmlValue
#' @importFrom XML xmlAttrs
#' @importFrom XML xmlName
#' @importFrom plyr rbind.fill.matrix
#' @importFrom dplyr rbind_all
#' @examples
#' baseURL <- "http://waterservices.usgs.gov/nwis/dv/?format=waterml,2.0"
#' URL <- paste(baseURL, "sites=01646500",
Expand Down Expand Up @@ -83,16 +83,7 @@ importWaterML2 <- function(obs_url, asDateTime=FALSE, tz=""){
chunk <- xmlDoc(timeSeries[[i]])
chunk <- xmlRoot(chunk)
chunkNS <- xmlNamespaceDefinitions(chunk, simplify = TRUE)

# xp <- xpathApply(chunk, "//wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP",
# xpathSApply, ".//*[not(*)]",
# function(x) setNames(ifelse(nzchar(xmlValue(x)),
# xmlValue(x),
# ifelse("qualifier" == xmlName(x),
# xpathSApply(x,"./@xlink:title",namespaces = ns),"")), #originally I had the "" as xmlAttr(x)
# xmlName(x)),
# namespaces = chunkNS)


xp <- xpathApply(chunk, "//wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP",
xpathSApply, ".//*[not(*)]",
function(x) setNames(ifelse(nzchar(xmlValue(x)),
Expand All @@ -108,9 +99,9 @@ importWaterML2 <- function(obs_url, asDateTime=FALSE, tz=""){
xp <- xp[-1]
}


DF2 <- do.call(rbind.fill.matrix, lapply(xp, t))
DF2 <- as.data.frame(DF2,stringsAsFactors=FALSE)
y <- lapply(xp,t)
z <- lapply(y, as.data.frame)
DF2 <- suppressWarnings(rbind_all(z))

names(DF2)[grep("wml2",names(DF2))] <- sub("wml2:","",names(DF2)[grep("wml2",names(DF2))])

Expand Down Expand Up @@ -150,11 +141,7 @@ importWaterML2 <- function(obs_url, asDateTime=FALSE, tz=""){
} else {
DF2$qualifier <- rep(defaultQualifier,nrow(DF2))
}


# DF2$qualifier <- ifelse("Provisional data subject to revision." == DF2$qualifier, "P",
# ifelse("Approved for publication. Processing and review completed." == DF2$qualifier, "A", DF2$qualifier))


#########################################

id <- as.character(xpathApply(chunk, "//gml:identifier", xmlValue, namespaces = chunkNS))
Expand Down

0 comments on commit 83dc1c6

Please sign in to comment.