Skip to content

Commit 57ea2df

Browse files
committed
upstream
Merge branch 'main' of github.com:DOI-USGS/dataRetrieval into develop # Conflicts: # tutorials/images/publish.png
2 parents 0dd8860 + 1bbf4b3 commit 57ea2df

File tree

8 files changed

+73
-10
lines changed

8 files changed

+73
-10
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ tests/manual/*
104104
vignettes/qwdata_changes.Rmd
105105
vignettes/nwisData.rds
106106
vignettes/wqpData.rds
107+
_quarto.yml

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dataRetrieval 2.7.21
44
* Added deprecation warning to readNWISgwl and readNWISmeas.
55
* Added parent_time_series_id to read_waterdata_ts_meta.
66
* Updated some documentation.
7+
* Handle waterdata empty returns better.
78

89
dataRetrieval 2.7.20
910
===================

R/read_waterdata.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,18 @@ read_waterdata <- function(service,
8787

8888
return_list <- walk_pages(data_req, max_results)
8989

90-
return_list <- deal_with_empty(return_list, args[["properties"]], service)
90+
if(is.null(args[["skipGeometry"]])){
91+
skipGeometry <- FALSE
92+
} else if (is.na(args[["skipGeometry"]])){
93+
skipGeometry <- FALSE
94+
} else {
95+
skipGeometry <- args[["skipGeometry"]]
96+
}
97+
98+
return_list <- deal_with_empty(return_list, args[["properties"]],
99+
service,
100+
skipGeometry,
101+
convertType)
91102

92103
if(convertType) return_list <- cleanup_cols(return_list)
93104

R/walk_pages.R

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#' @param properties A vector of requested columns
55
#' @param service character, can be any existing collection such
66
#' as "daily", "monitoring-locations", "time-series-metadata"
7+
#' @param skipGeometry A logical for whether to return geometry
8+
#' @param convertType A logical for whether to convert value to numeric
79
#'
810
#' @return data.frame
911
#' @noRd
@@ -17,17 +19,50 @@
1719
#' properties = NA,
1820
#' service = "daily")
1921
#'
20-
deal_with_empty <- function(return_list, properties, service){
22+
deal_with_empty <- function(return_list, properties, service,
23+
skipGeometry,
24+
convertType){
25+
2126
if(nrow(return_list) == 0){
2227

2328
if(all(is.na(properties))){
2429
schema <- check_OGC_requests(endpoint = service, type = "schema")
2530
properties <- names(schema$properties)
2631
}
27-
return_list <- data.frame(matrix(nrow = 0, ncol = length(properties)))
32+
return_list <- data.frame(matrix(nrow = 0,
33+
ncol = length(properties)))
34+
return_list <- lapply(return_list, as.character)
2835
names(return_list) <- properties
36+
37+
single_params <- c("datetime", "last_modified", "begin", "end", "time")
38+
39+
for(i in single_params){
40+
if(i %in% names(return_list)){
41+
return_list[[i]] <- as.POSIXct(as.character(), origin = "1970-01-01")
42+
}
43+
}
44+
45+
if(convertType && service == "daily"){
46+
return_list$time <- as.Date(as.character())
47+
}
48+
49+
if(convertType && "value" %in% names(return_list)){
50+
return_list$value <- as.numeric()
51+
}
52+
53+
if(convertType && "contributing_drainage_area" %in% names(return_list)){
54+
return_list$contributing_drainage_area <- as.numeric()
55+
}
56+
57+
return_list <- data.frame(return_list)
58+
return_list$geometry <- NULL
59+
60+
if(!skipGeometry){
61+
return_list <- sf::st_as_sf(return_list, geometry = sf::st_sfc())
62+
}
63+
2964
}
30-
65+
3166
return(return_list)
3267
}
3368

@@ -271,7 +306,14 @@ get_ogc_data <- function(args,
271306

272307
return_list <- walk_pages(req, max_results)
273308

274-
return_list <- deal_with_empty(return_list, properties, service)
309+
if(is.na(args[["skipGeometry"]])){
310+
skipGeometry <- FALSE
311+
} else {
312+
skipGeometry <- args[["skipGeometry"]]
313+
}
314+
315+
return_list <- deal_with_empty(return_list, properties, service,
316+
skipGeometry, convertType)
275317

276318
if(convertType) return_list <- cleanup_cols(return_list, service = service)
277319

tests/testthat/tests_general.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ test_that("General USGS retrievals working", {
2727
dv_data <- read_waterdata(service = "daily",
2828
CQL = cql,
2929
time = c("2023-01-01", "2024-01-01"))
30+
3031
expect_equal(as.Date(c("2023-01-01", "2024-01-01")),
3132
range(dv_data$time))
3233
expect_true(all(unique(dv_data$monitoring_location_id) %in%

tests/testthat/tests_userFriendly_fxns.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test_that("Unit value data returns correct types", {
6868
context("Peak, rating, meas, site")
6969
test_that("peak, rating curves, surface-water measurements", {
7070
testthat::skip_on_cran()
71-
skip_on_ci()
71+
testthat::skip_on_ci()
7272
siteNumbers <- c("01594440", "040851325")
7373
data <- readNWISpeak(siteNumbers)
7474
expect_is(data$agency_cd, "character")
@@ -120,7 +120,8 @@ test_that("peak, rating curves, surface-water measurements", {
120120

121121
test_that("read_waterdata_daily", {
122122
testthat::skip_on_cran()
123-
123+
testthat::skip_on_ci()
124+
124125
siteNumber <- "USGS-04085427"
125126
startDate <- "2012-01-01"
126127
endDate <- "2012-06-30"
@@ -153,6 +154,12 @@ test_that("read_waterdata_daily", {
153154
parameter_code = "00060",
154155
time = c("2014-01-01", "2014-01-07"))
155156
expect_true(nrow(notActiveUSGS) == 0)
157+
expect_type(notActiveUSGS$value, "double")
158+
notActiveUSGS2 <- read_waterdata_daily(monitoring_location_id = paste0("USGS-", site),
159+
parameter_code = "00060",
160+
convertType = FALSE,
161+
time = c("2014-01-01", "2014-01-07"))
162+
expect_type(notActiveUSGS2$value, "character")
156163

157164
})
158165

vignettes/basic_slides.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ editor_options:
1212
chunk_output_type: console
1313
---
1414

15-
Click the slide below then "f" for full screen, and "Esc" to escape full screen.
15+
For a direct link to the slides, go [here](https://doi-usgs.github.io/dataRetrieval/tutorials/basic_slides_deck.html). Use the arrow keys to advance the slides. Or click the slide below then "f" for full screen, and "Esc" to escape full screen.
1616

1717
```{=html}
18-
<iframe src="../tutorials/basic_slides_deck.html" width="700"
18+
<iframe src="../tutorials/basic_slides_deck.html" width="800"
1919
height="400"></iframe>
2020
```
2121

vignettes/changes_slides.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ editor_options:
1212
chunk_output_type: console
1313
---
1414

15-
Click the slide below then "f" for full screen, and "Esc" to escape full screen.
15+
For a direct link to the slides, go [here](https://doi-usgs.github.io/dataRetrieval/tutorials/changes_slides_deck.html). Use the arrow keys to advance the slides. Or click the slide below then "f" for full screen, and "Esc" to escape full screen.
1616

1717
```{=html}
1818
<iframe src="../tutorials/changes_slides_deck.html" width="700"

0 commit comments

Comments
 (0)