Skip to content

Commit 8ae0119

Browse files
committed
Realized if a NA gets in a "comma parameter", it was removing that query altogether, causing WAY more data to be returned than intended.
1 parent 9515c0b commit 8ae0119

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

R/construct_api_requests.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,20 @@ construct_api_requests <- function(service,
6464
warning("No filtering arguments specified.")
6565
}
6666
# Figure out if the GET request will be > 2048 characters
67-
comma_params_filtered <- Filter(Negate(anyNA), full_list[comma_params])
68-
67+
# and remove NA's from the comma parameters
68+
comma_params_filtered <- Filter(Negate(anyNA), lapply(full_list[comma_params], function(x) x[!is.na(x)]))
69+
comma_params_filtered <- comma_params_filtered[!sapply(comma_params_filtered,is.null)]
70+
71+
single_params_filtered <- Filter(Negate(anyNA), full_list[single_params])
72+
single_params_filtered <- single_params_filtered[!sapply(single_params_filtered,is.null)]
73+
6974
force_post <- nchar(paste0(unlist(comma_params_filtered), collapse = ",")) > 2048
7075

7176
if(force_post){
72-
get_list <- full_list[names(full_list) %in% c(single_params)]
77+
get_list <- single_params_filtered
7378
} else {
7479
# GET list refers to arguments that will go in the URL no matter what (not POST)
75-
get_list <- full_list[names(full_list) %in% c(single_params, comma_params)]
80+
get_list <- c(single_params_filtered, comma_params_filtered)
7681
}
7782

7883
get_list[["skipGeometry"]] <- skipGeometry

tests/testthat/tests_userFriendly_fxns.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,10 @@ test_that("pCode Stuff", {
463463
expect_equal(nrow(paramINFO), 3)
464464
expect_true(all(paramINFO$parameter_code %in% c("00060", "01075", "00931")))
465465

466+
paramINFO <- read_waterdata_parameter_codes(parameter_code = c("00060", "01075", "00931", NA))
467+
expect_equal(nrow(paramINFO), 3)
468+
expect_true(all(paramINFO$parameter_code %in% c("00060", "01075", "00931")))
469+
466470
# pcode 12345 isn't a valid code:
467471
paramINFO <- read_waterdata_parameter_codes(c("12345"))
468472
expect_true(nrow(paramINFO) == 0)

0 commit comments

Comments
 (0)