Skip to content
Snippets Groups Projects
Commit 15665a1e authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Added date checker to data and sites function.

parent a56067f5
No related branches found
No related tags found
1 merge request!65Date checker.
...@@ -93,6 +93,8 @@ ...@@ -93,6 +93,8 @@
#' startDate <- as.Date("2013-01-01") #' startDate <- as.Date("2013-01-01")
#' nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate=startDate, #' nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate=startDate,
#' characteristicType="Nutrient") #' characteristicType="Nutrient")
#' nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate="",
#' characteristicType="Nutrient")
#' } #' }
readWQPdata <- function(...){ readWQPdata <- function(...){
...@@ -108,31 +110,7 @@ readWQPdata <- function(...){ ...@@ -108,31 +110,7 @@ readWQPdata <- function(...){
values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox']) values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox'])
} }
dateNames <- c("startDateLo","startDateHi","startDate","endDate") values <- checkWQPdates(values)
if(any(names(values) %in% dateNames)){
index <- which(names(values) %in% dateNames)
if("" %in% values[index]){
values <- values[-index[values[index] == ""]]
index <- which(names(values) %in% dateNames)
}
if(length(index) > 0){
# If a valid R date was put in, the format needs to be changed to mm-dd-yyyy for the WQP:
if(any(!is.na(as.Date(values[index], format="%Y-%m-%d")))){
dates <- as.Date(values[index[!is.na(as.Date(values[index], format="%Y-%m-%d"))]])
dates <- format(as.Date(dates), format="%m-%d-%Y")
values[index] <- dates
} else if (any(is.na(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) == 'startDate'] <- 'startDateLo'
names(values)[names(values) == 'endDate'] <- 'startDateHi'
}
}
urlCall <- paste(paste(names(values),values,sep="="),collapse="&") urlCall <- paste(paste(names(values),values,sep="="),collapse="&")
......
...@@ -69,31 +69,7 @@ whatWQPsites <- function(...){ ...@@ -69,31 +69,7 @@ whatWQPsites <- function(...){
values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox']) values['bBox'] <- gsub(pattern = ";", replacement = ",", x = values['bBox'])
} }
dateNames <- c("startDateLo","startDateHi","startDate","endDate") values <- checkWQPdates(values)
if(any(names(values) %in% dateNames)){
index <- which(names(values) %in% dateNames)
if("" %in% values[index]){
values <- values[-index[values[index] == ""]]
index <- which(names(values) %in% dateNames)
}
if(length(index) > 0){
# If a valid R date was put in, the format needs to be changed to mm-dd-yyyy for the WQP:
if(any(!is.na(as.Date(values[index], format="%Y-%m-%d")))){
dates <- as.Date(values[index[!is.na(as.Date(values[index], format="%Y-%m-%d"))]])
dates <- format(as.Date(dates), format="%m-%d-%Y")
values[index] <- dates
} else if (any(is.na(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) == 'startDate'] <- 'startDateLo'
names(values)[names(values) == 'endDate'] <- 'startDateHi'
}
}
urlCall <- paste(paste(names(values),values,sep="="),collapse="&") urlCall <- paste(paste(names(values),values,sep="="),collapse="&")
......
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/checkWQPdates.r
\name{checkWQPdates}
\alias{checkWQPdates}
\title{Date Check for Water Quality Portal}
\usage{
checkWQPdates(values)
}
\arguments{
\item{values}{named list with arguments to send to the Water Quality Portal}
}
\value{
values named list with corrected arguments to send to the Water Quality Portal
}
\description{
Checks date format for inputs to the Water Quality Portal. Used in \code{readWQPqw}
and \code{readWQPdata}.
}
\examples{
values <- list(startDateLo="01-01-2002", characteristicName="Phosphorous",
endDate=as.Date("2014-01-01"))
values <- checkWQPdates(values)
}
...@@ -102,6 +102,8 @@ pHDataExpanded2 <- readWQPdata(bBox=c(-90.10,42.67,-88.64,43.35),characteristicN ...@@ -102,6 +102,8 @@ pHDataExpanded2 <- readWQPdata(bBox=c(-90.10,42.67,-88.64,43.35),characteristicN
startDate <- as.Date("2013-01-01") startDate <- as.Date("2013-01-01")
nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate=startDate, nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate=startDate,
characteristicType="Nutrient") characteristicType="Nutrient")
nutrientDaneCounty <- readWQPdata(countycode="US:55:025",startDate="",
characteristicType="Nutrient")
} }
} }
\keyword{WQP} \keyword{WQP}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment