Commit 80689983 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

pr

Merge branch 'master' of github.com:USGS-R/dataRetrieval

# Conflicts:
#	.gitignore
parents 5d6d0ebb b87d4480
......@@ -2,3 +2,5 @@
.Rhistory
.RData
.Ruserdata
dataRetrieval.Rproj
.gitignore
......@@ -5,6 +5,7 @@
#'
#' @param values named list with arguments to send to the Water Quality Portal
#' @return values named list with corrected arguments to send to the Water Quality Portal
#' @importFrom lubridate parse_date_time
#' @export
#' @keywords internal
#' @examples
......@@ -29,8 +30,8 @@ checkWQPdates <- function(values){
splitDates <- unlist(strsplit(dateInput, "-"))
if(length(splitDates) == 3){
if(nchar(splitDates[1]) == 4){ #R object
dates <- as.Date(dateInput, format="%Y-%m-%d")
dates <- format(as.Date(dates), format="%m-%d-%Y")
dates <- as.Date(parse_date_time(dateInput, "%Y-%m-%d"))
dates <- format(dates, format="%m-%d-%Y")
values[i] <- dates
} else if (nchar(splitDates[3]) != 4){ #The way WQP wants it == 4, so this is probably a 2 digit year or something
warning("Please check the date format for the arguments: ",
......
......@@ -35,6 +35,7 @@
#' }
#'
#' @seealso \code{\link{renameNWISColumns}}, \code{\link{importWaterML1}}
#' @importFrom lubridate parse_date_time
#' @export
#' @keywords data import USGS web service
#' @examples
......
......@@ -146,7 +146,7 @@ readNWISpeak <- function (siteNumbers,startDate="",endDate="", asDateTime=TRUE,
} else {
data$peak_dt <- as.Date(data$peak_dt, format="%Y-%m-%d")
}
if(any(is.na(data$peak_dt))) {
if(anyNA(data$peak_dt)){
message("Some dates could not be converted to a valid date, and were returned as NA")
}
}
......
......@@ -185,7 +185,7 @@ readWQPdata <- function(..., querySummary=FALSE, tz="UTC"){
valueType=retval$ResultSampleFractionText,
stringsAsFactors=FALSE)
if(any(!is.na(variableInfo$parameterCd))){
if(!anyNA(variableInfo$parameterCd)){
pcodes <- unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)])
pcodes <- pcodes["" != pcodes]
paramINFO <- readNWISpCode(pcodes)
......
......@@ -162,7 +162,7 @@ readWQPqw <- function(siteNumbers,parameterCd,startDate="",endDate="",tz="UTC",
stringsAsFactors=FALSE)
variableInfo <- unique(variableInfo)
if(any(!is.na(variableInfo$parameterCd))){
if(!anyNA(variableInfo$parameterCd)){
pcodes <- unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)])
pcodes <- pcodes["" != pcodes]
paramINFO <- readNWISpCode(pcodes)
......
......@@ -73,7 +73,7 @@ whatNWISdata <- function(siteNumbers,service="all",parameterCd="all",statCd="all
}
if(!("all" %in% parameterCd)){
if(any(!is.na(parameterCd))){
if(anyNA(parameterCd)){
pcodeCheck <- all(nchar(parameterCd) == 5) & all(!is.na(suppressWarnings(as.numeric(parameterCd))))
if(!pcodeCheck){
......
......@@ -20,7 +20,7 @@ zeroPad <- function(x,padTo){
numDigits <- nchar(x, keepNA = TRUE)
padding <- padTo-numDigits
if(any(is.na(padding))){
if(anyNA(padding)){
padding[is.na(padding)] <- 0
}
......
......@@ -309,3 +309,31 @@ test_that("NGWMN functions working", {
expect_equal(attr(tzDataMT$dateTime, 'tzone'), "US/Mountain")
expect_warning(tzDataUTC$dateTime == tzDataMT$dateTime)
})
context("getWebServiceData")
test_that("long urls use POST", {
url <- paste0(rep("reallylongurl", 200), collapse = '')
with_mock(
RETRY = function(method, ...) {
return(method == "POST")
},
status_code = function(resp) 200,
headers = function(resp) list(`content-type` = "logical"),
content = function(resp, encoding) resp,
expect_true(getWebServiceData(url)),
.env = "httr"
)
})
test_that("ngwmn urls don't use post", {
url <- paste0(rep("urlwithngwmn", 200), collapse = '')
with_mock(
RETRY = function(method, ...) {
return(method == "POST")
},
status_code = function(resp) 200,
headers = function(resp) list(`content-type` = "logical"),
content = function(resp, encoding) resp,
expect_false(getWebServiceData(url)),
.env = "httr"
)
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment