Skip to content

Commit 3276276

Browse files
Merge pull request #769 from DOI-USGS/revert-767-develop
Revert "Develop"
2 parents 6f00ece + d86fe7c commit 3276276

19 files changed

+162
-300
lines changed

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.18.9002
4+
Version: 2.7.18
55
Authors@R: c(
66
person("Laura", "DeCicco", role = c("aut","cre"),
77
email = "ldecicco@usgs.gov",

R/AAA.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ is_legacy <- function(service){
4646
}
4747

4848
nwis_message <- function(){
49-
return("WARNING: whatNWISdata does not include
50-
discrete water quality data newer than March 11, 2024.
51-
For additional details, see:
49+
return("WARNING: NWIS does not deliver
50+
discrete water quality data newer than March 11, 2024
51+
or updates to existing data. For additional details, see:
5252
https://doi-usgs.github.io/dataRetrieval/articles/Status.html")
5353
}

R/constructNWISURL.R

Lines changed: 64 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,8 @@ constructNWISURL <- function(siteNumbers,
7979
service[service == "meas"] <- "measurements"
8080
service[service == "uv"] <- "iv"
8181

82-
POST = nchar(paste0(siteNumbers, parameterCd, collapse = "")) > 2048
83-
8482
baseURL <- httr2::request(pkg.env[[service]])
8583

86-
if(!is.null(pkg.env$access)){
87-
baseURL <- httr2::req_url_query(baseURL, Access = pkg.env$access)
88-
}
89-
9084
if (any(!is.na(parameterCd) & parameterCd != "all")) {
9185
pcodeCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
9286

@@ -103,60 +97,43 @@ constructNWISURL <- function(siteNumbers,
10397
switch(service,
10498
rating = {
10599
ratingType <- match.arg(ratingType, c("base", "corr", "exsa"))
106-
url <- get_or_post(baseURL,
107-
POST = POST,
108-
site_no = siteNumbers,
109-
file_type = ratingType)
100+
url <- httr2::req_url_query(baseURL,
101+
site_no = siteNumbers,
102+
file_type = ratingType)
110103
},
111104
peak = {
112-
url <- get_or_post(baseURL,
113-
POST = POST,
105+
url <- httr2::req_url_query(baseURL,
114106
range_selection = "date_range",
115107
format = "rdb")
116-
url <- get_or_post(url,
117-
POST = POST,
118-
site_no = siteNumbers,
119-
.multi = "comma")
120-
108+
url <- httr2::req_url_query(url,
109+
site_no = siteNumbers,
110+
.multi = "comma")
121111
if (nzchar(startDate)) {
122-
url <- get_or_post(url,
123-
POST = POST,
124-
begin_date = startDate)
112+
url <- httr2::req_url_query(url, begin_date = startDate)
125113
}
126114
if (nzchar(endDate)) {
127-
url <- get_or_post(url,
128-
POST = POST,
129-
end_date = endDate)
115+
url <- httr2::req_url_query(url, end_date = endDate)
130116
}
131117
},
132118
measurements = {
133-
url <- get_or_post(baseURL,
134-
POST = POST,
119+
url <- httr2::req_url_query(baseURL,
135120
site_no = siteNumbers,
136121
.multi = "comma")
137-
url <- get_or_post(url,
138-
POST = POST,
139-
range_selection = "date_range"
122+
url <- httr2::req_url_query(url,
123+
range_selection = "date_range"
140124
)
141125
if (nzchar(startDate)) {
142-
url <- get_or_post(url,
143-
POST = POST,
126+
url <- httr2::req_url_query(url,
144127
begin_date = startDate
145128
)
146129
}
147130
if (nzchar(endDate)) {
148-
url <- get_or_post(url,
149-
POST = POST,
150-
end_date = endDate)
131+
url <- httr2::req_url_query(url, end_date = endDate)
151132
}
152133
if (expanded) {
153-
url <- get_or_post(url,
154-
POST = POST,
155-
format = "rdb_expanded")
134+
url <- httr2::req_url_query(url, format = "rdb_expanded")
156135
} else {
157-
url <- get_or_post(url,
158-
POST = POST,
159-
format = "rdb")
136+
url <- httr2::req_url_query(url, format = "rdb")
160137
}
161138
},
162139
stat = { # for statistics service
@@ -181,62 +158,42 @@ constructNWISURL <- function(siteNumbers,
181158
stop("Start and end dates for annual statReportType can only include years")
182159
}
183160

184-
url <- get_or_post(baseURL,
185-
POST = POST,
161+
url <- httr2::req_url_query(baseURL,
186162
sites = siteNumbers,
187163
.multi = "comma")
188-
url <- get_or_post(url,
189-
POST = POST,
190-
statReportType = statReportType,
191-
.multi = "comma")
192-
url <- get_or_post(url,
193-
POST = POST,
194-
statType = statType,
195-
.multi = "comma")
196-
url <- get_or_post(url,
197-
POST = POST,
198-
parameterCd = parameterCd,
199-
.multi = "comma")
164+
url <- httr2::req_url_query(url,
165+
statReportType = statReportType,
166+
.multi = "comma")
167+
url <- httr2::req_url_query(url, statType = statType,
168+
.multi = "comma")
169+
url <- httr2::req_url_query(url, parameterCd = parameterCd,
170+
.multi = "comma")
200171

201172
if (nzchar(startDate)) {
202-
url <- get_or_post(url,
203-
POST = POST,
204-
startDT = startDate)
173+
url <- httr2::req_url_query(url, startDT = startDate)
205174
}
206175
if (nzchar(endDate)) {
207-
url <- get_or_post(url,
208-
POST = POST,
209-
endDT = endDate)
176+
url <- httr2::req_url_query(url, endDT = endDate)
210177
}
211178
if (!grepl("(?i)daily", statReportType)) {
212-
url <- get_or_post(url,
213-
POST = POST,
214-
missingData = "off")
179+
url <- httr2::req_url_query(url, missingData = "off")
215180
}
216181
},
217182
gwlevels = {
218-
url <- get_or_post(baseURL,
219-
POST = POST,
220-
site_no = siteNumbers,
221-
.multi = "comma")
222-
url <- get_or_post(url,
223-
POST = POST,
224-
format = "rdb")
183+
184+
url <- httr2::req_url_query(baseURL,
185+
site_no = siteNumbers, .multi = "comma")
186+
url <- httr2::req_url_query(url,format = "rdb")
225187
if (nzchar(startDate)) {
226-
url <- get_or_post(url,
227-
POST = POST,
228-
begin_date = startDate)
188+
url <- httr2::req_url_query(url, begin_date = startDate)
229189
}
230190
if (nzchar(endDate)) {
231-
url <- get_or_post(url,
232-
POST = POST,
233-
end_date = endDate)
191+
url <- httr2::req_url_query(url, end_date = endDate)
234192
}
235-
url <- get_or_post(url,
236-
POST = POST,
237-
group_key = "NONE",
238-
date_format = "YYYY-MM-DD",
239-
rdb_compression = "value")
193+
url <- httr2::req_url_query(url,
194+
group_key = "NONE",
195+
date_format = "YYYY-MM-DD",
196+
rdb_compression = "value")
240197
},
241198
{ # this will be either dv, uv, groundwater
242199

@@ -250,44 +207,34 @@ constructNWISURL <- function(siteNumbers,
250207
wml1 = "waterml,1.1"
251208
)
252209

253-
url <- get_or_post(baseURL,
254-
POST = POST,
255-
site = siteNumbers,
256-
.multi = "comma")
257-
url <- get_or_post(url,
258-
POST = POST,
259-
format = formatURL)
210+
url <- httr2::req_url_query(baseURL,
211+
site = siteNumbers,
212+
.multi = "comma")
213+
url <- httr2::req_url_query(url,
214+
format = formatURL)
260215

261216
if (!all(is.na(parameterCd))) {
262-
url <- get_or_post(url,
263-
POST = POST,
264-
ParameterCd = parameterCd,
265-
.multi = "comma")
217+
url <- httr2::req_url_query(url,
218+
ParameterCd = parameterCd,
219+
.multi = "comma")
266220
}
267221

268222
if ("dv" == service) {
269-
url <- get_or_post(url,
270-
POST = POST,
271-
StatCd = statCd,
272-
.multi = "comma")
223+
url <- httr2::req_url_query(url,
224+
StatCd = statCd,
225+
.multi = "comma")
273226
}
274227

275228
if (nzchar(startDate)) {
276-
url <- get_or_post(url,
277-
POST = POST,
278-
startDT = startDate)
229+
url <- httr2::req_url_query(url, startDT = startDate)
279230
} else {
280231
startorgin <- "1851-01-01"
281232
if ("iv" == service) startorgin <- "1900-01-01"
282-
url <- get_or_post(url,
283-
POST = POST,
284-
startDT = startorgin)
233+
url <- httr2::req_url_query(url, startDT = startorgin)
285234
}
286235

287236
if (nzchar(endDate)) {
288-
url <- get_or_post(url,
289-
POST = POST,
290-
endDT = endDate)
237+
url <- httr2::req_url_query(url, endDT = endDate)
291238
}
292239
}
293240
)
@@ -353,8 +300,6 @@ constructWQPURL <- function(siteNumbers,
353300

354301
pCodeLogic <- TRUE
355302

356-
POST = nchar(paste0(siteNumbers, collapse = "")) > 2048
357-
358303
if(!allPCode){
359304
multiplePcodes <- length(parameterCd) > 1
360305
if (all(nchar(parameterCd) == 5)) {
@@ -366,13 +311,11 @@ constructWQPURL <- function(siteNumbers,
366311

367312
if(legacy){
368313
baseURL <- httr2::request(pkg.env[["Result"]])
369-
baseURL <- get_or_post(baseURL,
370-
POST = POST,
371-
siteid = siteNumbers,
372-
.multi = function(x) paste0(x, collapse = ";"))
373-
baseURL <- get_or_post(baseURL,
374-
POST = POST,
375-
count = "no")
314+
baseURL <- httr2::req_url_query(baseURL,
315+
siteid = siteNumbers,
316+
.multi = function(x) paste0(x, collapse = ";"))
317+
baseURL <- httr2::req_url_query(baseURL,
318+
count = "no")
376319
} else {
377320
baseURL <- httr2::request(pkg.env[["ResultWQX3"]])
378321
baseURL <- httr2::req_url_query(baseURL,
@@ -382,10 +325,9 @@ constructWQPURL <- function(siteNumbers,
382325

383326
if(legacy & !allPCode){
384327
if(pCodeLogic){
385-
baseURL <- get_or_post(baseURL,
386-
POST = POST,
387-
pCode = parameterCd,
388-
.multi = function(x) paste0(x, collapse = ";"))
328+
baseURL <- httr2::req_url_query(baseURL,
329+
pCode = parameterCd,
330+
.multi = function(x) paste0(x, collapse = ";"))
389331
} else {
390332
baseURL <- httr2::req_url_query(baseURL,
391333
characteristicName = parameterCd,
@@ -406,20 +348,17 @@ constructWQPURL <- function(siteNumbers,
406348

407349
if (nzchar(startDate)) {
408350
startDate <- format(as.Date(startDate), format = "%m-%d-%Y")
409-
baseURL <- get_or_post(baseURL,
410-
POST = POST,
411-
startDateLo = startDate)
351+
baseURL <- httr2::req_url_query(baseURL,
352+
startDateLo = startDate)
412353
}
413354

414355
if (nzchar(endDate)) {
415356
endDate <- format(as.Date(endDate), format = "%m-%d-%Y")
416-
baseURL <- get_or_post(baseURL,
417-
POST = POST,
418-
startDateHi = endDate)
357+
baseURL <- httr2::req_url_query(baseURL,
358+
startDateHi = endDate)
419359
}
420360

421-
baseURL <- httr2::req_url_query(baseURL,
422-
mimeType = "csv")
361+
baseURL <- httr2::req_url_query(baseURL, mimeType = "csv")
423362
if(!legacy){
424363
baseURL <- httr2::req_url_query(baseURL,
425364
dataProfile = "basicPhysChem")

R/dataRetrievals-package.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ NULL
8989

9090
#' US State Code Lookup Table
9191
#'
92-
#' Classic lookup table for states. Has been replaced in functions with
93-
#' \code{check_param("states")}.
92+
#' Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/state.txt}
93+
#' on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
94+
#' file found in inst/extdata, which is used internally with NWIS retrievals.
9495
#'
9596
#' @name stateCd
9697
#' @return stateCd data frame.
@@ -111,8 +112,9 @@ NULL
111112

112113
#' US County Code Lookup Table
113114
#'
114-
#' Classic lookup table for counties. Has been replaced in functions with
115-
#' \code{check_param("counties")}.
115+
#' Data originally pulled from \url{https://www2.census.gov/geo/docs/reference/codes/files/national_county.txt}
116+
#' on April 1, 2015. On Feb. 11, 2022, the fields were updated with the
117+
#' file found in inst/extdata, which is used internally with NWIS retrievals.
116118
#'
117119
#' @name countyCd
118120
#' @return countyCd data frame.

R/findNLDI.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ valid_ask <- function(all, type) {
270270
#' ## Find feature by NWIS ID
271271
#' findNLDI(nwis = "11120000")
272272
#'
273+
#' ## Find feature by WQP ID
274+
#' findNLDI(wqp = "USGS-04024315")
273275
#'
274276
#' ## Find feature by LOCATION
275277
#' findNLDI(location = c(-115, 40))
@@ -288,14 +290,14 @@ valid_ask <- function(all, type) {
288290
#' # Discover Features(flowlines will not be returned unless included in find)
289291
#'
290292
#' ## Find feature(s) on the upper tributary of USGS-11120000
291-
#' findNLDI(nwis = "11120000", nav = "UT", find = c("nwis"))
293+
#' findNLDI(nwis = "11120000", nav = "UT", find = c("nwis", "wqp"))
292294
#'
293295
#' ## Find upstream basin boundary and of USGS-11120000
294296
#' findNLDI(nwis = "11120000", find = "basin")
295297
#'
296298
#' # Control Distance
297299
#' ## Limit search to 50 km
298-
#' findNLDI(comid = 101, nav = "DM", find = c("nwis", "flowlines"), distance_km = 50)
300+
#' findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
299301
#' }
300302

301303
findNLDI <- function(comid = NULL,

R/getWebServiceData.R

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,14 @@ getWebServiceData <- function(obs_url, ...) {
2525
return(invisible(NULL))
2626
}
2727

28-
if(is.character(obs_url)){
29-
obs_url <- httr2::request(obs_url)
30-
}
31-
3228
obs_url <- httr2::req_user_agent(obs_url, default_ua())
3329
obs_url <- httr2::req_throttle(obs_url, rate = 30 / 60)
3430
obs_url <- httr2::req_retry(obs_url,
3531
backoff = ~ 5, max_tries = 3)
3632
obs_url <- httr2::req_headers(obs_url,
3733
`Accept-Encoding` = c("compress", "gzip"))
3834

39-
url_method <- "GET"
40-
if(!is.null(obs_url$body)){
41-
url_method <- "POST"
42-
}
43-
message(url_method, ": ", obs_url$url)
35+
message("GET:", obs_url$url)
4436
returnedList <- httr2::req_perform(obs_url)
4537

4638
good <- check_non_200s(returnedList)

0 commit comments

Comments
 (0)