Skip to content

Commit 39f307a

Browse files
Merge pull request #747 from ldecicco-USGS/develop
Develop
2 parents 1460f56 + 9e3a66d commit 39f307a

File tree

14 files changed

+184
-100
lines changed

14 files changed

+184
-100
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ jobs:
2121
matrix:
2222
config:
2323
- {os: macos-latest, r: 'release'}
24-
- {os: windows-latest, r: 'release'}
25-
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
26-
- {os: ubuntu-latest, r: 'release'}
27-
- {os: ubuntu-latest, r: 'oldrel-1'}
2824

2925
env:
3026
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pkgdown.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ jobs:
3030
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3131
CUSTOM_DR_UA: 'GitHub_CI'
3232
steps:
33-
- uses: actions/checkout@c0a81a463886bb75afe234e07a9fd5bb79219196
33+
- uses: actions/checkout@581d62f320f2a4043a1ea6ac77290c60d27485cc
3434

35-
- uses: r-lib/actions/setup-pandoc@52330cc136b963487918a8867f948ddf954e9e63
35+
- uses: r-lib/actions/setup-pandoc@473c68190595b311a74f208fba61a8d8c0d4c247
3636

37-
- uses: r-lib/actions/setup-r@52330cc136b963487918a8867f948ddf954e9e63
37+
- uses: r-lib/actions/setup-r@473c68190595b311a74f208fba61a8d8c0d4c247
3838
with:
3939
use-public-rspm: true
4040

41-
- uses: r-lib/actions/setup-r-dependencies@52330cc136b963487918a8867f948ddf954e9e63
41+
- uses: r-lib/actions/setup-r-dependencies@473c68190595b311a74f208fba61a8d8c0d4c247
4242
with:
4343
extra-packages: |
4444
any::pkgdown
@@ -58,7 +58,7 @@ jobs:
5858
file.copy(from = "./public/articles/logo.png",to = "./public/reference/logo.png")
5959
shell: Rscript {0}
6060
- name: Upload artifact
61-
uses: actions/upload-pages-artifact@64bcae551a7b18bcb9a09042ddf1960979799187
61+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa
6262
with:
6363
path: ./public
6464
# Deployment job
@@ -71,5 +71,5 @@ jobs:
7171
steps:
7272
- name: Deploy to GitHub Pages
7373
id: deployment
74-
uses: actions/deploy-pages@73e62e651178eeba977de2dc9f4c7645b3d01015
74+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e
7575

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dataRetrieval
22
Type: Package
33
Title: Retrieval Functions for USGS and EPA Hydrology and Water Quality Data
4-
Version: 2.7.17.9001
4+
Version: 2.7.18
55
Authors@R: c(
66
person("Laura", "DeCicco", role = c("aut","cre"),
77
email = "[email protected]",

R/getWebServiceData.R

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,6 @@ getWebServiceData <- function(obs_url, ...) {
5252
content <- gsub(" ", "", tolower(headerInfo$`content-type`))
5353
if (content %in% return_content) {
5454
returnedDoc <- httr2::resp_body_string(returnedList)
55-
trys <- 1
56-
if (all(grepl("ERROR: INCOMPLETE DATA", returnedDoc))) {
57-
58-
while(trys <= 3){
59-
message("Trying again!")
60-
obs_url <- httr2::req_url_query(obs_url,
61-
try = trys)
62-
returnedList <- httr2::req_perform(obs_url)
63-
64-
good <- check_non_200s(returnedList)
65-
if(good){
66-
returnedDoc <- httr2::resp_body_string(returnedList)
67-
}
68-
if (all(grepl("ERROR: INCOMPLETE DATA", returnedDoc))) {
69-
trys <- trys + 1
70-
} else {
71-
trys <- 100
72-
}
73-
}
74-
}
75-
76-
# } else if (headerInfo$`content-type` %in% return_raw) {
77-
# returnedDoc <- httr2::resp_body_raw(returnedList)
7855
} else if (content %in% return_readLines) {
7956
returnedList <- httr2::resp_body_string(returnedList)
8057
txt <- readLines(returnedList$content)

R/importWQP.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ importWQP <- function(obs_url, tz = "UTC",
6767

6868
attr(retval, 'spec') <- NULL
6969

70+
if(any(grepl("ERROR: INCOMPLETE DATA", retval[1,]))){
71+
stop(retval[[1]])
72+
}
73+
7074
# this is only needed for legacy
7175
names(retval)[grep("/", names(retval))] <- gsub("/", ".", names(retval)[grep("/", names(retval))])
7276

R/readWQPdata.R

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
#'
4444
#' @param \dots see \url{https://www.waterqualitydata.us/webservices_documentation} for a complete list of options.
4545
#' A list of arguments can also be supplied. For more information see the above
46-
#' description for this help file. If no "service" argument is supplied, it
47-
#' will default to "ResultWQX3". One way to figure out how to construct a WQP query is to go to the "Advanced"
46+
#' description for this help file. One way to figure out how to construct a WQP query is to go to the "Advanced"
4847
#' form in the Water Quality Portal. Use the form to discover what parameters are available. Once the query is
4948
#' set in the form, scroll down to the "Query URL". You will see the parameters
5049
#' after "https://www.waterqualitydata.us/#". For example, if you chose "Nutrient"
@@ -86,12 +85,21 @@
8685
#' @examplesIf is_dataRetrieval_user()
8786
#' \donttest{
8887
#'
88+
#' # Legacy:
8989
#' nameToUse <- "pH"
9090
#' pHData <- readWQPdata(siteid = "USGS-04024315",
9191
#' characteristicName = nameToUse)
9292
#' ncol(pHData)
9393
#' attr(pHData, "siteInfo")
9494
#' attr(pHData, "queryTime")
95+
#' attr(pHData, "url")
96+
#'
97+
#' # WQX3:
98+
#' pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315",
99+
#' characteristicName = nameToUse,
100+
#' service = "ResultWQX3",
101+
#' dataProfile = "basicPhysChem")
102+
#' attr(pHData_wqx3, "url")
95103
#'
96104
#' # More examples:
97105
#' # querying by county
@@ -101,11 +109,30 @@
101109
#' characteristicName = "Nitrogen"
102110
#' )
103111
#'
112+
#' attr(DeWitt, "url")
113+
#'
114+
#' DeWitt_wqx3 <- readWQPdata(
115+
#' statecode = "Illinois",
116+
#' countycode = "DeWitt",
117+
#' characteristicName = "Nitrogen",
118+
#' service = "ResultWQX3",
119+
#' dataProfile = "basicPhysChem",
120+
#' ignore_attributes = TRUE)
121+
#'
122+
#' attr(DeWitt_wqx3, "url")
123+
#'
104124
#' # Data profile: "Sampling Activity"
105125
#' activity <- readWQPdata(
106126
#' siteid = "USGS-04024315",
107127
#' service = "Activity"
108128
#' )
129+
#' attr(activity, "url")
130+
#'
131+
#' activity_wqx3 <- readWQPdata(
132+
#' siteid = "USGS-04024315",
133+
#' service = "ActivityWQX3"
134+
#' )
135+
#' attr(activity_wqx3, "url")
109136
#'
110137
#' Dane_activity <- readWQPdata(
111138
#' statecode = "Wisconsin",
@@ -114,14 +141,20 @@
114141
#' startDateHi = "2023-12-31",
115142
#' service = "Activity"
116143
#' )
144+
#' attr(Dane_activity, "url")
145+
#'
146+
#' Dane_activity_wqx3 <- readWQPdata(
147+
#' statecode = "Wisconsin",
148+
#' countycode = "Dane",
149+
#' startDateLo = "2023-01-01",
150+
#' startDateHi = "2023-12-31",
151+
#' service = "ActivityWQX3"
152+
#' )
153+
#' attr(Dane_activity_wqx3, "url")
117154
#'
118155
#' ########################################################
119156
#' # Additional examples:
120157
#'
121-
#' pHData_legacy <- readWQPdata(siteid = "USGS-04024315",
122-
#' characteristicName = nameToUse,
123-
#' service = "Result",
124-
#' dataProfile = "narrowResult")
125158
#'
126159
#' # Data profiles: "Organization Data"
127160
#' org_data <- readWQPdata(
@@ -157,6 +190,7 @@
157190
#' dataProfile = "biological",
158191
#' service = "Result"
159192
#' )
193+
#'
160194
#'
161195
#' # Data profiles: "Sample Results (narrow)"
162196
#' samp_narrow <- readWQPdata(
@@ -165,6 +199,13 @@
165199
#' dataProfile = "narrowResult"
166200
#' )
167201
#'
202+
#' samp_narrow_wqx3 <- readWQPdata(
203+
#' siteid = "USGS-04024315",
204+
#' service = "ResultWQX3",
205+
#' dataProfile = "narrow"
206+
#' )
207+
#'
208+
#'
168209
#' # Data profiles: "Sampling Activity"
169210
#' samp_activity <- readWQPdata(
170211
#' siteid = "USGS-04024315",
@@ -289,6 +330,29 @@ readWQPdata <- function(...,
289330

290331
create_WQP_attributes <- function(retval, ...){
291332

333+
col_legacy <- c("CharacteristicName", #legacy
334+
"ResultMeasure.MeasureUnitCode",
335+
"ResultSampleFractionText")
336+
col_wqx3 <- c("Result_Characteristic", #wqx3
337+
"Result_MeasureUnit",
338+
"Result_SampleFraction")
339+
if (all(col_legacy %in% names(retval))) {
340+
retvalVariableInfo <- retval[, col_legacy]
341+
retvalVariableInfo <- unique(retvalVariableInfo)
342+
names(retvalVariableInfo) <- c("characteristicName",
343+
"param_units",
344+
"valueType")
345+
346+
attr(retval, "variableInfo") <- retvalVariableInfo
347+
} else if(all(col_wqx3 %in% names(retval))){
348+
retvalVariableInfo <- retval[, col_wqx3]
349+
retvalVariableInfo <- unique(retvalVariableInfo)
350+
names(retvalVariableInfo) <- c("characteristicName",
351+
"param_units",
352+
"valueType")
353+
354+
attr(retval, "variableInfo") <- retvalVariableInfo
355+
}
292356

293357
siteInfo <- suppressWarnings(whatWQPsites(..., legacy = attr(retval, "legacy")))
294358
attr(retval, "siteInfo") <- siteInfo
@@ -301,8 +365,6 @@ create_WQP_attributes <- function(retval, ...){
301365
attr(retval, "queryTime") <- Sys.time()
302366
}
303367

304-
305-
306368
return(retval)
307369
}
308370

R/readWQPdots.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ readWQPdots <- function(..., legacy = TRUE) {
7777
# in WQP, but if they also then request county codes,
7878
# it gets really confusing, and the WQP developers don't recommend.
7979
values["countycode"] <- countyCdLookup(stCd, values["countycode"], "fips")
80+
# WQP doesn't need or want both state and county code:
81+
values["statecode"] <- NULL
8082
}
8183

8284
if(!"mimeType" %in% names(values)){

R/readWQPqw.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,24 @@
5555
#'
5656
#' attr(rawPcode, "siteInfo")
5757
#' attr(rawPcode, "queryTime")
58-
#'
58+
#' attr(rawPcode, "url")
5959
#'
6060
#' rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "")
61-
#' rawPHsites <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), "pH", "", "")
61+
#' pHsites_legacy <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"),
62+
#' "pH", "", "")
63+
#' ncol(pHsites_legacy)
64+
#' attr(pHsites_legacy, "url")
65+
#'
66+
#' pHsites_modern <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"),
67+
#' "pH", "", "", legacy = FALSE)
68+
#' ncol(pHsites_modern)
69+
#' attr(pHsites_modern, "url")
70+
#'
6271
#' nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20")
6372
#'
64-
#' SC <- readWQPqw(siteNumbers = "USGS-05288705", parameterCd = "00300", convertType = FALSE)
73+
#' DO <- readWQPqw(siteNumbers = "USGS-05288705",
74+
#' parameterCd = "00300",
75+
#' convertType = FALSE)
6576
#' }
6677
readWQPqw <- function(siteNumbers,
6778
parameterCd,

README.Rmd

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,9 @@ library(dataRetrieval)
2929

3030
The `dataRetrieval` package was created to simplify the process of loading hydrologic data into the R environment. It is designed to retrieve the major data types of U.S. Geological Survey (USGS) hydrology data that are available on the Web, as well as data from the Water Quality Portal (WQP), which currently houses water quality data from the Environmental Protection Agency (EPA), U.S. Department of Agriculture (USDA), and USGS. Direct USGS data is obtained from a service called the National Water Information System (NWIS).
3131

32-
:warning: USGS discrete water-quality data availability and format are changing. Beginning March 11, 2024 USGS data obtained from legacy services will not include new USGS data or recent updates to existing data. To view the status of changes in data availability and code functionality, visit: <https://doi-usgs.github.io/dataRetrieval/articles/Status.html>
33-
34-
:warning: All documentation on <https://doi-usgs.github.io/dataRetrieval> assume you have the development version of dataRetrieval installed. To do that:
32+
# Introduction
3533

36-
```{r eval=FALSE}
37-
library(remotes)
38-
install_github("DOI-USGS/dataRetrieval",
39-
build_vignettes = TRUE,
40-
build_opts = c("--no-resave-data",
41-
"--no-manual"))
42-
```
34+
:warning: USGS discrete water-quality data availability and format are changing. Beginning March 11, 2024 USGS data obtained from legacy services will not include new USGS data or recent updates to existing data. To view the status of changes in data availability and code functionality, visit: <https://doi-usgs.github.io/dataRetrieval/articles/Status.html>
4335

4436
If you have additional questions about these changes, email [email protected].
4537

0 commit comments

Comments
 (0)