Unverified Commit 23dbe84f authored by Laura A DeCicco's avatar Laura A DeCicco Committed by GitHub
Browse files

Merge pull request #576 from ldecicco-USGS/master

Getting leading zeros back
parents 870cbfe5 6674f524
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.7.7.0001
Version: 2.7.9.0001
Authors@R: c(
person("Laura", "DeCicco", role = c("aut","cre"),
email = "ldecicco@usgs.gov",
......
......@@ -2,7 +2,7 @@ dataRetrieval 2.7.8
==================
* Fixed missing comments in readNWISqw
* Added Stable Isotopes, Habitat, and Other water quality groupings
* Added option to not check for headers on WQP requests.
* Adding options for updated readr
dataRetrieval 2.7.7
==================
......
......@@ -44,7 +44,7 @@ getWebServiceData <- function(obs_url, ...){
returnedDoc <- returnedList
} else if (headerInfo$`content-type` %in% c("text/html",
"text/html; charset=UTF-8") ){
txt <- readBin(returnedList$content, character())
txt <- readLines(returnedList$content)
message(txt)
return(txt)
} else {
......
......@@ -112,17 +112,25 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz="UTC"){
header.names <- strsplit(readr.total[meta.rows+1],"\t")[[1]]
types.names <- strsplit(readr.total[meta.rows+2],"\t")[[1]]
data.rows <- total.rows - meta.rows - 2
char.names <- c(header.names[grep("_cd",header.names)],
header.names[grep("_id",header.names)],
header.names[grep("_tx",header.names)],
header.names[grep("_tm",header.names)],
header.names[header.names == "site_no"],
header.names[header.names == "project_no"])
if(data.rows > 0){
args_list <- list(file = f,
delim = "\t",
skip = meta.rows + 2,
col_names = FALSE)
if(utils::packageVersion("readr") > 1.9){
if(utils::packageVersion("readr") > 1.4){
args_list[["show_col_types"]] <- FALSE
}
if(convertType){
args_list[["guess_max"]] <- data.rows
args_list[["guess_max"]] <- data.rows
args_list[["col_types"]] <- readr::cols()
} else {
args_list[["col_types"]] <- readr::cols(.default = "c")
}
......@@ -138,6 +146,21 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz="UTC"){
readr.data <- as.data.frame(readr.data)
if(length(char.names) > 0){
char.names.true <- char.names[sapply(readr.data[,char.names], is.character)]
char.names <- char.names[!(char.names %in% char.names.true)]
}
if(length(char.names) > 0){
args_list[["col_types"]] <- readr::cols(.default = "c")
readr.data.char <- do.call(readr::read_delim, args = args_list)
names(readr.data.char) <- header.names
for(j in char.names){
readr.data[,j] <- readr.data.char[[j]]
}
}
if(convertType){
if(length(grep("_va", names(readr.data))) > 0 ){
......
......@@ -30,7 +30,8 @@
#' STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
#' STORETdata <- importWQP(STORETex)
#' }
importWQP <- function(obs_url, zip=TRUE, tz="UTC", csv=FALSE){
importWQP <- function(obs_url, zip=TRUE, tz="UTC",
csv=FALSE){
if(tz != ""){
tz <- match.arg(tz, OlsonNames())
......
......@@ -78,6 +78,7 @@ whatNWISdata <- function(..., convertType=TRUE){
if("parameterCd" %in% names(matchReturn)){
parameterCd <- matchReturn$parameterCd
matchReturn[["parameterCd"]] <- NULL
} else {
parameterCd <- "all"
}
......
......@@ -11,10 +11,10 @@ bibentry(bibtype = "Manual",
title = "dataRetrieval: R packages for discovering and retrieving water data available from U.S. federal hydrologic web services",
publisher = "U.S. Geological Survey",
address="Reston, VA",
version = "2.7.7",
version = "2.7.8",
institution = "U.S. Geological Survey",
year = 2018,
year = 2021,
doi = "10.5066/P9X4L3GE",
url = "https://code.usgs.gov/water/dataRetrieval",
textVersion = "De Cicco, L.A., Hirsch, R.M., Lorenz, D., Watkins, W.D., 2018, dataRetrieval: R packages for discovering and retrieving water data available from Federal hydrologic web services, doi:10.5066/P9X4L3GE"
textVersion = "De Cicco, L.A., Hirsch, R.M., Lorenz, D., Watkins, W.D., 2021, dataRetrieval: R packages for discovering and retrieving water data available from Federal hydrologic web services, doi:10.5066/P9X4L3GE"
)
......@@ -74,6 +74,7 @@ test_that("peak, rating curves, surface-water measurements", {
siteINFO <- readNWISsite('05114000')
expect_is(siteINFO$agency_cd, 'character')
expect_equal(siteINFO$site_no, '05114000')
siteINFOMulti <- readNWISsite(c('05114000','09423350'))
expect_true(nrow(siteINFOMulti) == 2)
......@@ -82,10 +83,15 @@ test_that("peak, rating curves, surface-water measurements", {
expect_is(Meas07227500.ex$measurement_dt, 'Date')
expect_is(Meas07227500.ex$measurement_dateTime, 'POSIXct')
expect_error(whatNWISdata(siteNumber = "10312000",parameterCd = "50286"))
expect_equal(nrow(whatNWISdata(siteNumber = "10312000",parameterCd = "50286")), 0)
expect_equal(ncol(whatNWISdata(siteNumber = "10312000",parameterCd = "50286")), 24)
url <- "https://waterservices.usgs.gov/nwis/site/?format=rdb&seriesCatalogOutput=true&sites=05114000"
x <- importRDB1(url)
siteID <- "263819081585801"
gwl_1 <- readNWISgwl(siteID)
expect_equal(unique(gwl_1$site_no), siteID)
})
......@@ -201,7 +207,7 @@ test_that("readNWISuse tests", {
testthat::skip_on_cran()
dc <- readNWISuse(years=c(2000,2005,2010),stateCd = "DC", countyCd = NULL)
expect_true(nrow(dc)==3)
expect_is(dc$state_cd, 'numeric')
expect_is(dc$state_cd, 'character')
ohio <- readNWISuse(years=2005,stateCd="OH",countyCd="ALL")
expect_true(nrow(ohio)==88)
......
......@@ -165,9 +165,9 @@ kable(data.df,
```
Two output columns that may not be obvious are "srsname" and "casrn". Srsname stands for "Substance Registry Services". More information on the srs name can be found [here](http://ofmpub.epa.gov/sor_internet/registry/substreg/home/overview/home.do).
Two output columns that may not be obvious are "srsname" and "casrn". Srsname stands for "Substance Registry Services". More information on the srs name can be found [here](https://sor.epa.gov/sor_internet/registry/substreg/home/overview/home.do).
Casrn stands for "Chemical Abstracts Service (CAS) Registry Number". More information on CAS can be found [here](http://www.cas.org/support/documentation/chemical-substances/faqs).
Casrn stands for "Chemical Abstracts Service (CAS) Registry Number". More information on CAS can be found [here](https://www.cas.org/support/documentation/chemical-substances/faqs).
For unit values data (sensor data measured at regular time intervals such as 15 minutes or hourly), knowing the parameter code and `siteNumber` is enough to make a request for data. For most variables that are measured on a continuous basis, the USGS also stores the historical data as daily values. These daily values are statistical summaries of the continuous data, e.g. maximum, minimum, mean, or median. The different statistics are specified by a 5-digit statistics code.
......
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