diff --git a/DESCRIPTION b/DESCRIPTION index fa8c262c16d6f490c15b4e25692e067ca9aea80a..21c952b2e20342448e8c91dcdb71d8059e5dac49 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 ec9caeccb53571d495e4f6fb5124981ad060c01b..8160be3aa2076bae0546c95537f6720411e3789f 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="&")