From 705a438571f2cc6c7babec6f27d5b1e2e30f80b5 Mon Sep 17 00:00:00 2001 From: Laura A DeCicco Date: Mon, 5 Aug 2024 19:47:30 -0500 Subject: [PATCH 1/2] Handle "all" better in readWQPqw --- R/constructNWISURL.R | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/R/constructNWISURL.R b/R/constructNWISURL.R index b10f79ab..efe0b190 100644 --- a/R/constructNWISURL.R +++ b/R/constructNWISURL.R @@ -356,37 +356,44 @@ constructWQPURL <- function(siteNumbers, endDate, legacy = FALSE) { - multiplePcodes <- length(parameterCd) > 1 - - if (all(nchar(parameterCd) == 5)) { - suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(parameterCd)))) - } else { - pCodeLogic <- FALSE - parameterCd <- sapply(parameterCd, utils::URLencode, USE.NAMES = FALSE, reserved = TRUE) + allPCode <- any(parameterCd %in% c("all", "All")) + if(!allPCode){ + multiplePcodes <- length(parameterCd) > 1 + + if (all(nchar(parameterCd) == 5)) { + suppressWarnings(pCodeLogic <- all(!is.na(as.numeric(parameterCd)))) + } else { + pCodeLogic <- FALSE + parameterCd <- sapply(parameterCd, utils::URLencode, USE.NAMES = FALSE, reserved = TRUE) + } + pcode_name <- ifelse(pCodeLogic, "pCode", "characteristicName") } - pcode_name <- ifelse(pCodeLogic, "pCode", "characteristicName") - - if(legacy){ + if(legacy & !allPCode){ if (multiplePcodes) { parameterCd <- paste(parameterCd, collapse = ";") } parameterCd <- paste0(pcode_name, "=", parameterCd) - siteNumbers <- paste(siteNumbers, collapse = ";") - baseURL <- drURL("Result", siteid = siteNumbers, Access = pkg.env$access) - } else { + } else if(!legacy & !allPCode){ parameterCd <- paste0(pcode_name, "=", parameterCd) if (multiplePcodes) { parameterCd <- paste0(parameterCd, collapse = "&") } - + } + + if(legacy){ + siteNumbers <- paste(siteNumbers, collapse = ";") + baseURL <- drURL("Result", siteid = siteNumbers, Access = pkg.env$access) + } else { siteNumbers <- paste(paste0("siteid=", siteNumbers), collapse = "&") baseURL <- drURL("ResultWQX3", Access = pkg.env$access) baseURL <- paste0(baseURL, siteNumbers) } - baseURL <- paste0(baseURL, "&", parameterCd) + if(!allPCode){ + baseURL <- paste0(baseURL, "&", parameterCd) + } if (nzchar(startDate)) { startDate <- format(as.Date(startDate), format = "%m-%d-%Y") From bfc891b9a858252b7aaea21a4f47e6252e33c398 Mon Sep 17 00:00:00 2001 From: Laura A DeCicco Date: Tue, 6 Aug 2024 06:52:49 -0500 Subject: [PATCH 2/2] just use toupper --- R/constructNWISURL.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/constructNWISURL.R b/R/constructNWISURL.R index efe0b190..a949419e 100644 --- a/R/constructNWISURL.R +++ b/R/constructNWISURL.R @@ -356,7 +356,7 @@ constructWQPURL <- function(siteNumbers, endDate, legacy = FALSE) { - allPCode <- any(parameterCd %in% c("all", "All")) + allPCode <- any(toupper(parameterCd) == "ALL") if(!allPCode){ multiplePcodes <- length(parameterCd) > 1