Commit 08846c17 authored by David Watkins's avatar David Watkins
Browse files

fix xml_find_all hanging up

parent 86ce3449
...@@ -161,9 +161,9 @@ importWaterML2 <- function(input, asDateTime=FALSE, tz="UTC") { ...@@ -161,9 +161,9 @@ importWaterML2 <- function(input, asDateTime=FALSE, tz="UTC") {
time = character(0), dateTime = character(0), value = numeric(0), time = character(0), dateTime = character(0), value = numeric(0),
uom = character(0), comment = character(0), stringsAsFactors = FALSE)) uom = character(0), comment = character(0), stringsAsFactors = FALSE))
} }
rawTime <- xml_text(xml_find_all(TVP,".//wml2:time")) rawTime <- xml_text(xml_find_all(returnedDoc, "./wml2:point/wml2:MeasurementTVP/wml2:time"))
valueNodes <- xml_find_all(TVP,".//wml2:value") valueNodes <- xml_find_all(returnedDoc,"./wml2:point/wml2:MeasurementTVP/wml2:value")
values <- as.numeric(xml_text(valueNodes)) values <- as.numeric(xml_text(valueNodes))
nVals <- length(values) nVals <- length(values)
...@@ -192,9 +192,13 @@ importWaterML2 <- function(input, asDateTime=FALSE, tz="UTC") { ...@@ -192,9 +192,13 @@ importWaterML2 <- function(input, asDateTime=FALSE, tz="UTC") {
uom <- xml_attr(valueNodes, "uom", default = NA) uom <- xml_attr(valueNodes, "uom", default = NA)
source <- xml_attr(xml_find_all(TVP, ".//wml2:source"), "title") source <- xml_attr(xml_find_all(returnedDoc,
comment <- xml_text(xml_find_all(TVP, ".//wml2:comment")) "./wml2:point/wml2:MeasurementTVP/wml2:metadata/wml2:source"),
tvpQuals <- xml_text(xml_find_all(TVP, ".//swe:description")) "title")
comment <- xml_text(xml_find_all(returnedDoc,
"./wml2:point/wml2:MeasurementTVP/wml2:metadata/wml2:comment"))
tvpQuals <- xml_text(xml_find_all(returnedDoc,
"./wml2:point/wml2:MeasurementTVP/wml2:metadata/swe:description"))
defaultMeta <- xml_find_all(returnedDoc, ".//wml2:DefaultTVPMeasurementMetadata") defaultMeta <- xml_find_all(returnedDoc, ".//wml2:DefaultTVPMeasurementMetadata")
defaultQuals <- xml_text(xml_find_all(defaultMeta, ".//swe:description")) defaultQuals <- xml_text(xml_find_all(defaultMeta, ".//swe:description"))
defaultUOM <- xml_attr(xml_find_all(defaultMeta, ".//wml2:uom"), "title", default = NA) defaultUOM <- xml_attr(xml_find_all(defaultMeta, ".//wml2:uom"), "title", default = NA)
......
...@@ -346,7 +346,7 @@ check_if_xml <- function(obs_url){ ...@@ -346,7 +346,7 @@ check_if_xml <- function(obs_url){
returnedDoc <- read_xml(obs_url) returnedDoc <- read_xml(obs_url)
}else if(class(obs_url) == 'raw'){ }else if(class(obs_url) == 'raw'){
returnedDoc <- read_xml(obs_url) returnedDoc <- read_xml(obs_url)
} else if(class(obs_url) == "xml_node"){ } else if(inherits(obs_url, c("xml_node", "xml_nodeset"))) {
returnedDoc <- obs_url returnedDoc <- obs_url
} else { } else {
returnedDoc <- xml_root(getWebServiceData(obs_url, encoding='gzip')) returnedDoc <- xml_root(getWebServiceData(obs_url, encoding='gzip'))
......
...@@ -352,7 +352,7 @@ test_that("NGWMN functions working", { ...@@ -352,7 +352,7 @@ test_that("NGWMN functions working", {
expect_is(tzDataUTC$dateTime, "POSIXct") expect_is(tzDataUTC$dateTime, "POSIXct")
expect_is(tzDataMT$dateTime, "POSIXct") expect_is(tzDataMT$dateTime, "POSIXct")
expect_equal(attr(tzDataMT$dateTime, 'tzone'), "US/Mountain") expect_equal(attr(tzDataMT$dateTime, 'tzone'), "US/Mountain")
expect_warning(tzDataUTC$dateTime == tzDataMT$dateTime) expect_equal(attr(tzDataUTC$dateTime, 'tzone'), "UTC")
}) })
context("getWebServiceData") context("getWebServiceData")
......
...@@ -180,9 +180,9 @@ context("importWaterML2") ...@@ -180,9 +180,9 @@ context("importWaterML2")
test_that("importWaterML2 internal test", { test_that("importWaterML2 internal test", {
filePath <- system.file("extdata", package="dataRetrieval") filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML2Example.xml" fileName <- "WaterML2Example.xml"
fullPath <- file.path(filePath, fileName) xml_full <- xml2::read_xml(file.path(filePath, fileName))
UserData <- importWaterML2(fullPath) measurementTS <- xml2::xml_find_all(xml_full, "//wml2:MeasurementTimeseries")
# saveRDS(UserData, "rds/UserData.rds") UserData <- importWaterML2(measurementTS)
expect_is(UserData$value, 'numeric') expect_is(UserData$value, 'numeric')
# expect_is(UserData$qualifier, 'character') # expect_is(UserData$qualifier, 'character')
...@@ -191,8 +191,9 @@ test_that("importWaterML2 internal test", { ...@@ -191,8 +191,9 @@ test_that("importWaterML2 internal test", {
test_that("importWaterML2 external test", { test_that("importWaterML2 external test", {
testthat::skip_on_cran() testthat::skip_on_cran()
url <- "https://waterservices.usgs.gov/nwis/iv/?format=waterml,2.0&sites=01646500&parameterCd=00060,00065" url <- "https://waterservices.usgs.gov/nwis/iv/?format=waterml,2.0&sites=01646500&parameterCd=00060,00065"
exData <- importWaterML2(url) xml <- getWebServiceData(url)
# saveRDS(data, "rds/externalML2.rds") measurementTS2 <- xml2::xml_find_all(xml, "//wml2:MeasurementTimeseries")
exData <- importWaterML2(measurementTS2)
expect_is(exData$value, 'numeric') expect_is(exData$value, 'numeric')
expect_gt(nrow(exData),0) expect_gt(nrow(exData),0)
}) })
......
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