Skip to content

Commit 4d2312b

Browse files
committed
respect convertType
1 parent 9894b56 commit 4d2312b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

R/walk_pages.R

Lines changed: 15 additions & 3 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
@@ -18,7 +20,9 @@
1820
#' service = "daily")
1921
#'
2022
deal_with_empty <- function(return_list, properties, service,
21-
skipGeometry = TRUE){
23+
skipGeometry = TRUE,
24+
convertType = TRUE){
25+
2226
if(nrow(return_list) == 0){
2327

2428
if(all(is.na(properties))){
@@ -38,9 +42,17 @@ deal_with_empty <- function(return_list, properties, service,
3842
}
3943
}
4044

41-
if(service == "daily"){
45+
if(convertType && service == "daily"){
4246
return_list$time <- as.Date(as.character())
4347
}
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+
}
4456

4557
return_list <- data.frame(return_list)
4658
return_list$geometry <- NULL
@@ -301,7 +313,7 @@ get_ogc_data <- function(args,
301313
}
302314

303315
return_list <- deal_with_empty(return_list, properties, service,
304-
skipGeometry)
316+
skipGeometry, convertType)
305317

306318
if(convertType) return_list <- cleanup_cols(return_list, service = service)
307319

tests/testthat/tests_userFriendly_fxns.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ test_that("read_waterdata_daily", {
154154
parameter_code = "00060",
155155
time = c("2014-01-01", "2014-01-07"))
156156
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")
157163

158164
})
159165

0 commit comments

Comments
 (0)