From c526d1532214639512146d7b76468a40299bef4a Mon Sep 17 00:00:00 2001 From: unknown <ldecicco@usgs.gov> Date: Wed, 31 Dec 2014 11:25:31 -0600 Subject: [PATCH] Added same options to WQP sites function. --- DESCRIPTION | 4 ++-- R/whatWQPsites.R | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fa8c262c..21c952b2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: dataRetrieval Type: Package Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data -Version: 2.1.0 -Date: 2014-12-15 +Version: 2.1.1 +Date: 2015-01-02 Authors@R: c( person("Robert", "Hirsch", role = c("aut"), email = "rhirsch@usgs.gov"), person("Laura", "DeCicco", role = c("aut","cre"), diff --git a/R/whatWQPsites.R b/R/whatWQPsites.R index ec9caecc..8160be3a 100644 --- a/R/whatWQPsites.R +++ b/R/whatWQPsites.R @@ -59,13 +59,33 @@ whatWQPsites <- function(...){ matchReturn <- list(...) - options <- c("bBox","lat","long","within","countrycode","statecode","countycode","siteType","organization", - "siteid","huc","sampleMedia","characteristicType","characteristicName","pCode","activityId", - "startDateLo","startDateHi","mimeType","Zip","providers") - - if(!all(names(matchReturn) %in% options)) warning(matchReturn[!(names(matchReturn) %in% options)],"is not a valid query parameter to the Water Quality Portal") - - values <- sapply(matchReturn, function(x) URLencode(as.character(paste(eval(x),collapse="",sep="")))) + values <- sapply(matchReturn, function(x) URLencode(as.character(paste(eval(x),collapse=";",sep="")))) + + values <- gsub(",","%2C",values) + values <- gsub("%20","+",values) + values <- gsub(":","%3A",values) + + if("bBox" %in% names(values)){ + values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox']) + } + + dateNames <- c("startDateLo","startDateHi","startDate","endDate") + + if(any(names(values) %in% dateNames)){ + index <- which(names(values) %in% dateNames) + # If a valid R date was put in, the format needs to be changed to mm-dd-yyyy for the WQP: + if(all(is.Date(as.Date(values[index])))){ + dates <- as.Date(values[index]) + dates <- format(as.Date(dates), format="%m-%d-%Y") + values[index] <- dates + } else if (!all(is.Date(as.Date(values[index],format="%m-%d-%Y")))){ + warning("Please check the date format for the arguments: ", paste(names(values)[index], collapse=", ")) + } + + names(values)[names(values) == 'beginDate'] <- 'startDateLo' + names(values)[names(values) == 'endDate'] <- 'startDateHi' + + } urlCall <- paste(paste(names(values),values,sep="="),collapse="&") -- GitLab