Commit 4513780d authored by Laura A DeCicco's avatar Laura A DeCicco Committed by GitHub
Browse files

Merge pull request #353 from ldecicco-USGS/pCode

Fixes #351
parents 99422035 270551f6
......@@ -6,7 +6,6 @@
language: r
cache: packages
sudo: false
dist: trusty
matrix:
......@@ -30,8 +29,10 @@ env:
warnings_are_errors: true
install:
- travis_wait 30 Rscript -e "0"
script:
- |
R CMD build .
travis_wait 20 R CMD check dataRetrieval*tar.gz
r_github_packages:
- jimhester/covr
......
......@@ -28,8 +28,18 @@ readNWISpCode <- function(parameterCd){
parameterCd.orig <- parameterCd
parameterCd <- parameterCd[!is.na(parameterCd)]
baseURL <- drURL("pCode", Access=pkg.env$access)
fullURL <- appendDrURL(baseURL,radio_pm_search="param_group",
pm_group="All+--+include+all+parameter+groups",
show="parameter_group_nm",
show="parameter_nm",
show="casrn",
show="srsname",
show="parameter_units",
format="rdb")
if(any(parameterCd == "all")){
fullURL <- "https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=param_group&pm_group=All+--+include+all+parameter+groups&format=rdb&show=parameter_group_nm&show=parameter_nm&show=casrn&show=srsname&show=parameter_units"
parameterData <- importRDB1(fullURL, asDateTime = FALSE)
} else {
pcodeCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
......@@ -37,6 +47,16 @@ readNWISpCode <- function(parameterCd){
if(nrow(parameterData) != length(parameterCd)){
if(length(parameterCd) == 1){
suburl <- appendDrURL(baseURL,radio_pm_search="pm_search",
pm_search=parameterCd,
show="parameter_group_nm",
show="parameter_nm",
show="casrn",
show="srsname",
show="parameter_units",
format="rdb")
suburl <- paste0("https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=pm_search",
"&pm_search=", parameterCd,
"&format=rdb", "&show=parameter_group_nm",
......@@ -44,7 +64,7 @@ readNWISpCode <- function(parameterCd){
"&show=srsname", "&show=parameter_units")
parameterData <- importRDB1(suburl,asDateTime = FALSE)
} else {
fullURL <- "https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=param_group&pm_group=All+--+include+all+parameter+groups&format=rdb&show=parameter_group_nm&show=parameter_nm&show=casrn&show=srsname&show=parameter_units"
fullPcodeDownload <- importRDB1(fullURL)
parameterData <- fullPcodeDownload[fullPcodeDownload$parameter_cd %in% parameterCd,]
}
......@@ -62,7 +82,5 @@ readNWISpCode <- function(parameterCd){
parameterData <- rbind(parameterData, na.params)
}
return(parameterData)
}
......@@ -50,6 +50,7 @@ access = match.arg(access, c('public','internal','cooperator','USGS'))
pkg.env$qwdata = "https://nwis.waterdata.usgs.gov/nwis/qwdata"
pkg.env$stat = "https://waterservices.usgs.gov/nwis/stat/"
pkg.env$useNat = "https://waterdata.usgs.gov/nwis/water_use"
pkg.env$pCode = "https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes"
# NOTE: state water use are still in: constructUseURL
pkg.env$wqpData = "https://www.waterqualitydata.us/Result/search"
......
......@@ -391,4 +391,14 @@ test_that("Construct NWIS urls", {
rawSampleURL_Zip <- constructWQPURL('USGS-01594440','01075', '', '', TRUE)
expect_equal(rawSampleURL_Zip, "https://www.waterqualitydata.us/Result/search?siteid=USGS-01594440&pCode=01075&sorted=no&mimeType=tsv&zip=yes")
})
context("pCode Stuff")
test_that("pCode Stuff", {
paramINFO <- readNWISpCode(c('01075','00060','00931', NA))
expect_equal(nrow(paramINFO), 4)
paramINFO <- readNWISpCode("all")
expect_equal(attr(paramINFO, "url"),"https://nwis.waterdata.usgs.gov/nwis/pmcodes/pmcodes?radio_pm_search=param_group&pm_group=All+--+include+all+parameter+groups&show=parameter_group_nm&show=parameter_nm&show=casrn&show=srsname&show=parameter_units&format=rdb")
})
\ No newline at end of file
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