Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4fb4f84
Merge pull request #868 from ldecicco-USGS/develop
ldecicco-USGS Mar 10, 2026
acbed0e
Merge pull request #869 from ldecicco-USGS/develop
ldecicco-USGS Mar 10, 2026
7f6b6c5
set to character (we convert later)
ldecicco-USGS Mar 30, 2026
cd79c5f
Merge branch 'develop' of github.com:DOI-USGS/dataRetrieval into develop
ldecicco-USGS Mar 30, 2026
32599cd
getting ready for CRAN release
ldecicco-USGS Mar 30, 2026
76f55a1
test more things
ldecicco-USGS Mar 30, 2026
f79d3c8
Rebuilt triggers re-documenting
ldecicco-USGS Mar 30, 2026
e5a7788
Merge pull request #876 from ldecicco-USGS/develop
ldecicco-USGS Mar 31, 2026
7439c40
deal with missing x,y in csv
ldecicco-USGS Mar 31, 2026
144b8da
Merge branch 'main' of github.com:DOI-USGS/dataRetrieval into develop
ldecicco-USGS Mar 31, 2026
85087d9
retry_on_failure = TRUE
ldecicco-USGS Apr 15, 2026
99309d8
added chunking to daily
ldecicco-USGS Apr 16, 2026
01d15f8
Adding chunk_size as named argument
ldecicco-USGS Apr 16, 2026
ebc0c46
retry on error
ldecicco-USGS Apr 16, 2026
bd4f18f
Merge branch 'develop' of github.com:DOI-USGS/dataRetrieval into develop
ldecicco-USGS Apr 16, 2026
2f04f3d
clean up docs
ldecicco-USGS Apr 16, 2026
863bef5
Update version
ldecicco-USGS Apr 16, 2026
c31924a
Add ...s
ldecicco-USGS Apr 16, 2026
522786e
Rejigger parameters
ldecicco-USGS Apr 17, 2026
1710692
generalize the tests more
ldecicco-USGS Apr 17, 2026
c6771e0
Cleanup install pipeline
ldecicco-USGS Apr 17, 2026
ff87ae8
att attach argument
ldecicco-USGS Apr 17, 2026
8228252
?
ldecicco-USGS Apr 18, 2026
aa67bbe
Add first pass of read_waterdata_ratings
ldecicco-USGS Apr 22, 2026
c4aaca0
Clean up docs
ldecicco-USGS Apr 22, 2026
005a2a0
Add to docs
ldecicco-USGS Apr 22, 2026
58083ee
Added new reference lists
ldecicco-USGS Apr 23, 2026
bf2cbc5
Update R/read_waterdata_ratings.R
ldecicco-USGS Apr 24, 2026
3343503
Using file_type more effectively
ldecicco-USGS Apr 24, 2026
c1cda89
Merge branch 'develop' of github.com:ldecicco-USGS/dataRetrieval into…
ldecicco-USGS Apr 24, 2026
1a00759
Re-running docs with some updates from the API
ldecicco-USGS Apr 24, 2026
e2257af
Remove more tests that hit NWIS
ldecicco-USGS Apr 24, 2026
b95ee1f
Added data_type to comma, field_measurements_series_id to field measu…
ldecicco-USGS Apr 24, 2026
6fc79d5
clean up dots
ldecicco-USGS Apr 24, 2026
d583fbf
Add token message
ldecicco-USGS Apr 24, 2026
8be0492
use httr2 for download
ldecicco-USGS Apr 24, 2026
b0cd06e
does this work?
ldecicco-USGS Apr 27, 2026
2cf55c1
Move into docker folder
ldecicco-USGS Apr 27, 2026
dca100f
?
ldecicco-USGS Apr 27, 2026
b56d783
wrong symbol
ldecicco-USGS Apr 27, 2026
d66f077
rebuild docker
ldecicco-USGS Apr 27, 2026
1f51661
try to build docker again
ldecicco-USGS Apr 27, 2026
aa39d97
try again
ldecicco-USGS Apr 27, 2026
c9a2699
?
ldecicco-USGS Apr 27, 2026
a815d46
?
ldecicco-USGS Apr 27, 2026
8aa0b9b
test python
ldecicco-USGS Apr 27, 2026
57d6d09
Take out some old vignettes
ldecicco-USGS Apr 28, 2026
5d25c06
?
ldecicco-USGS Apr 28, 2026
02ff92a
?
ldecicco-USGS Apr 28, 2026
56c78b8
Can I get below 1 Gb image?
ldecicco-USGS Apr 28, 2026
1aadab4
call testthat instead of devtools
ldecicco-USGS Apr 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ vignettes/changes_slides.Rmd
vignettes/daily_data_statistics.Rmd
vignettes/continuous_pr.Rmd
vignettes/quick_slides.Rmd
vignettes/Reference_Lists.Rmd
^[.]?air[.]toml$
^\.vscode$
environment.yml
8 changes: 6 additions & 2 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ jobs:
any::pkgdown
any::rcmdcheck
any::DT
any::data.table
any::dplyr
any::tidyr
any::ggplot2
any::zoo
any::sf
any::patchwork
any::maps
Expand All @@ -59,6 +57,12 @@ jobs:
any::gridExtra
local::.
needs: website
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: environment.yml
cache-environment: false
cache-downloads: false
- name: Create public directory
run: |
mkdir public
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ docs
/doc/
/Meta/
/Temp/
/public/
vignettes/*.html
vignettes/*.R


/.quarto/

**/*.quarto_ipynb
32 changes: 22 additions & 10 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ build-image:
alias: docker
rules:
- changes:
- .gitlab-ci.yml
- docker/Dockerfile
- environment.yml
script:
- echo ${CI_REGISTRY_PASSWORD} | docker login -u ${CI_REGISTRY_USER} --password-stdin $CI_REGISTRY
- docker pull ${CI_REGISTRY_IMAGE}:latest || true
- cd docker
- docker build
-t ${CI_REGISTRY_IMAGE}:latest
.
- docker build --cache-from ${CI_REGISTRY_IMAGE}:latest -t ${CI_REGISTRY_IMAGE}:latest -t ${CI_REGISTRY_IMAGE}:BUILD_${CI_COMMIT_SHORT_SHA} -f docker/Dockerfile .
- docker push --all-tags ${CI_REGISTRY_IMAGE}

buildcheck:
Expand All @@ -58,8 +57,15 @@ buildcheck:
dependencies:
- build-image
script:
- Rscript -e 'devtools::install(quick = TRUE, upgrade = "never")'
- Rscript -e 'devtools::check(document = FALSE, args = "--no-tests", check_dir = Sys.getenv("BUILD_LOGS_DIR"), vignettes = FALSE)'
- |
Rscript -e "
rcmdcheck::rcmdcheck(
args = c('--no-manual', '--no-tests'),
build_args = c('--no-manual', '--no-resave-data'),
check_dir = '.',
error_on = 'warning'
)
"

unittests:
stage: test
Expand All @@ -68,8 +74,16 @@ unittests:
- build-image
- buildcheck
script:
- R -e 'library(testthat); options(testthat.output_file = file.path(Sys.getenv("CI_PROJECT_DIR"), "test-out.xml")); devtools::test(reporter = "junit")'
- R -e 'x <- covr::package_coverage(); covr::to_cobertura(x); x; '
- |
Rscript -e '
library(testthat)
options(testthat.output_file = file.path(Sys.getenv("CI_PROJECT_DIR"), "test-out.xml"))
test_local(reporter = "junit")'
- |
Rscript -e '
x <- covr::package_coverage()
covr::to_cobertura(x)
x'
artifacts:
when: always
expire_in: 1 week
Expand Down Expand Up @@ -100,11 +114,9 @@ pages:
- build-image
- buildcheck
script:
- Rscript -e 'devtools::install(quick = TRUE, upgrade = "never")'
- Rscript -e 'pkgdown::build_site(override = list(destination = "public"))'
- Rscript -e 'file.copy(from = "./public/articles/logo.png", to = "./public/reference/logo.png")'
- quarto render

artifacts:
paths:
- $PAGES_OUTDIR
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrology and Water Quality Data
Version: 2.7.23.9001
Version: 2.7.24.9001
Authors@R: c(
person("Laura", "DeCicco", role = c("aut","cre"),
email = "ldecicco@usgs.gov",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export(read_waterdata_latest_daily)
export(read_waterdata_metadata)
export(read_waterdata_monitoring_location)
export(read_waterdata_parameter_codes)
export(read_waterdata_ratings)
export(read_waterdata_samples)
export(read_waterdata_stats_daterange)
export(read_waterdata_stats_por)
Expand Down
18 changes: 18 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
dataRetrieval 2.7.25
===================
* Added read_waterdata_ratings to access USGS rating curves with
new modern endpoint.
* Increase flexibility of chunking by monitoring_location_id by
including it as an argument in each relevant function.
* Clean up deprecated code.
* Updated retry strategy to include retry_on_failure = TRUE.
* Added countries, methods, method-categories, method-citations, and
citations to possible values in read_waterdata_metadata.
* Added field_measurements_series_id argument to read_waterdata_field_measurement
* Removed NWIS tests



dataRetrieval 2.7.24
===================
* Let dataRetrieval take care of chunking up requests by monitoring_location_id.
* Fixed bug causing some character columns in importWQP to be numeric
* Fixed bug causing open ended date requests in waterdata funcitons to
return full period of record.

dataRetrieval 2.7.23
===================
Expand Down
15 changes: 15 additions & 0 deletions R/AAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pkg.env <- new.env()
options("dataRetrieval.api_version" = "v0")
options("dataRetrieval.api_version_stat" = "v0")
options("dataRetrieval.attach_request" = TRUE)
options("dataRetrieval.convertType" = TRUE)
options("dataRetrieval.no_paging" = FALSE)
options("dataRetrieval.site_chunk_size_meta" = 250)
options("dataRetrieval.site_chunk_size_data" = 10)
options("dataRetrieval.limit" = 50000)

services <- c(
"server",
Expand All @@ -32,7 +37,12 @@ pkg.env <- new.env()
"coordinate-method-codes",
"medium-codes",
"counties",
"countries",
"hydrologic-unit-codes",
"methods",
"method-categories",
"method-citations",
"citations",
"states",
"national-aquifer-codes",
"reliability-codes",
Expand All @@ -52,7 +62,12 @@ pkg.env <- new.env()
"coordinate_method_code",
"medium_code",
"county",
"country",
"hydrologic_unit_code",
"methods",
"method_categories",
"method_citations",
"citations",
"state",
"national_aquifer_code",
"reliability_code",
Expand Down
80 changes: 53 additions & 27 deletions R/construct_api_requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,67 @@
#'
#' @export
#' @param service Which service available on <https://api.waterdata.usgs.gov/ogcapi/v0/>.
#' @param output_id Name of id column to return
#' @param ... Extra parameters from the specific services.
#' @param bbox Only features that have a geometry that intersects the bounding
#' box are selected.The bounding box is provided as four or six numbers, depending
#' on whether the coordinate reference system includes a vertical axis (height or
#' depth).
#' @param properties The properties that should be included for each feature. The
#' parameter value is a comma-separated list of property names which depend on the
#' service being called.
#' @param skipGeometry This option can be used to skip response geometries for
#' each feature. The returning object will be a data frame with no spatial
#' information.
#' @keywords internal
#'
#' @inheritParams check_arguments_api
#' @inheritParams check_arguments_non_api
#'
#' @examples
#' site <- "USGS-02238500"
#' pcode <- "00060"
#' req_dv <- construct_api_requests("daily",
#' output_id = "daily_id",
#' monitoring_location_id = site,
#' parameter_code = "00060")
#'
#' req_dv <- construct_api_requests("daily",
#' output_id = "daily_id",
#' monitoring_location_id = site,
#' parameter_code = c("00060", "00065"))
#'
#' sites <- c("USGS-01491000", "USGS-01645000")
#' start_date <- "2018-01-01"
#' end_date <- "2022-01-01"
#' req_dv <- construct_api_requests("daily",
#' monitoring_location_id = sites,
#' parameter_code = c("00060", "00065"),
#' datetime = c(start_date, end_date))
#' output_id = "daily_id",
#' monitoring_location_id = sites,
#' parameter_code = c("00060", "00065"),
#' datetime = c(start_date, end_date))
#'
construct_api_requests <- function(
service,
properties = NA_character_,
output_id,
...,
bbox = NA,
skipGeometry = FALSE,
no_paging = FALSE,
...
convertType = getOption("dataRetrieval.convertType"),
no_paging = getOption("dataRetrieval.no_paging"),
chunk_size = getOption("dataRetrieval.site_chunk_size_data"),
limit = getOption("dataRetrieval.limit"),
attach_request = getOption("dataRetrieval.attach_request")
) {
POST <- FALSE

full_list <- list(...)
full_list[["limit"]] <- limit

check_arguments_non_api(
convertType = convertType,
no_paging = no_paging,
limit = full_list[["limit"]],
attach_request = attach_request,
chunk_size = chunk_size
)

check_arguments_api(
bbox = full_list[["bbox"]],
skipGeometry = full_list[["skipGeometry"]]
)

time_periods <- c(
"last_modified",
Expand All @@ -58,6 +77,20 @@ construct_api_requests <- function(
"end_utc"
)

full_list <- switch_arg_id(
full_list,
id_name = output_id,
service = service
)

# Clean out non-API arguments:
properties <- switch_properties_id(
properties = full_list[["properties"]],
id = output_id
)

full_list[["properties"]] <- NULL

if (any(time_periods %in% names(full_list))) {
for (i in time_periods[time_periods %in% names(full_list)]) {
dates <- FALSE
Expand All @@ -74,9 +107,10 @@ construct_api_requests <- function(
"begin",
"end",
"time",
"limit",
"begin_utc",
"end_utc"
"end_utc",
"limit",
"skipGeometry"
)

comma_params <- c(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated but a question: do you know if hydrologic_unit_codes from the monitoring-location endpoint is a single or comma parameter? I was just testing out passing a list of HUC8s in drpy, and I got an answer, but the count was way small and I don't even know what was actually used.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I last asked about that, huc's were not going to be comma parameters "any time soon" (so maybe someday?).

Remember HUCs are tricky. Our sites have a many combination of number of digits. So I think the issue was if you asked for c("012345", "012346"), you would only get those 2 HUCs, even if there were tons of sites with "01234567" and "01234678" for instance.

In dataRetrieval we send the HUC requests to a POST and that allows us to take advantage of the work the API developers put in to make HUCs special so that it really is going is as c("012345%", "012346%")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait! I forgot I set up the huc POST stuff specifically:
https://github.com/DOI-USGS/dataRetrieval/blob/develop/R/construct_api_requests.R#L498

Expand All @@ -85,7 +119,8 @@ construct_api_requests <- function(
"statistic_id",
"time_series_id",
"computation_period_identifier",
"computation_identifier"
"computation_identifier",
"data_type"
)

if (
Expand All @@ -110,6 +145,7 @@ construct_api_requests <- function(
Negate(anyNA),
lapply(full_list[comma_params], function(x) x[!is.na(x)])
)

comma_params_filtered <- comma_params_filtered[
!sapply(comma_params_filtered, is.null)
]
Expand All @@ -129,8 +165,6 @@ construct_api_requests <- function(
get_list <- c(single_params_filtered, comma_params_filtered)
}

get_list[["skipGeometry"]] <- skipGeometry

get_list <- get_list[!is.na(get_list)]

format_type <- ifelse(isTRUE(no_paging), "csv", "json")
Expand Down Expand Up @@ -207,15 +241,6 @@ construct_api_requests <- function(
return(baseURL)
}

check_limits <- function(args) {
current_api_limit <- 50000

if (is.na(args[["limit"]])) {
args[["limit"]] <- current_api_limit
}

return(args)
}

#' Setup the request for the OGC API requests
#'
Expand Down Expand Up @@ -595,6 +620,7 @@ basic_request <- function(url_base, format = "json") {
httr2::req_headers(`Accept-Encoding` = c("compress", "gzip")) |>
httr2::req_url_query(f = format, lang = "en-US") |>
httr2::req_error(body = error_body) |>
httr2::req_retry(max_tries = 3, retry_on_failure = TRUE) |>
httr2::req_timeout(seconds = 180)

req <- add_api_token(req)
Expand Down
2 changes: 1 addition & 1 deletion R/dataRetrieval-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ NULL
#
# property_list <- list()
# for(service in services){
# property_list[[service]] <- get_properties_for_docs(service)
# property_list[[service]] <- dataRetrieval:::get_properties_for_docs(service)
# }
#
# num_cols <- c("value", "contributing_drainage_area", "drainage_area",
Expand Down
6 changes: 5 additions & 1 deletion R/getWebServiceData.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ getWebServiceData <- function(obs_url, ...) {

obs_url <- httr2::req_user_agent(obs_url, default_ua())
obs_url <- httr2::req_throttle(obs_url, rate = 30 / 60)
obs_url <- httr2::req_retry(obs_url, max_tries = 3, max_seconds = 180)
obs_url <- httr2::req_retry(
obs_url,
max_tries = 3,
retry_on_failure = TRUE
)
obs_url <- httr2::req_headers(
obs_url,
`Accept-Encoding` = c("compress", "gzip")
Expand Down
Loading
Loading