Commit 9377d0c4 authored by Laura A DeCicco's avatar Laura A DeCicco Committed by GitHub
Browse files

Merge pull request #292 from ldecicco-USGS/master

http -> https
parents 2bc250c4 cd285ee2
Package: dataRetrieval Package: dataRetrieval
Type: Package Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.6.1 Version: 2.6.3
Date: 2016-08-26 Date: 2016-12-06
Authors@R: c( person("Robert", "Hirsch", role = c("aut"), Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"), email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"), person("Laura", "DeCicco", role = c("aut","cre"),
...@@ -25,11 +25,10 @@ Copyright: This software is in the public domain because it contains materials ...@@ -25,11 +25,10 @@ Copyright: This software is in the public domain because it contains materials
that originally came from the United States Geological Survey, an agency of that originally came from the United States Geological Survey, an agency of
the United States Department of Interior. For more information, see the the United States Department of Interior. For more information, see the
official USGS copyright policy at official USGS copyright policy at
http://www.usgs.gov/visual-id/credit_usgs.html#copyright https://www2.usgs.gov/visual-id/credit_usgs.html#copyright
Depends: Depends:
R (>= 3.0) R (>= 3.0)
Imports: Imports:
XML,
httr (>= 1.0.0), httr (>= 1.0.0),
curl, curl,
reshape2, reshape2,
......
...@@ -6,7 +6,7 @@ pkg.env <- new.env() ...@@ -6,7 +6,7 @@ pkg.env <- new.env()
} }
.onAttach = function(libname, pkgname){ .onAttach = function(libname, pkgname){
packageStartupMessage("Recent changes to NWIS data may affect dataRetrieval output. packageStartupMessage("USGS is switching from http to https:
Please see http://help.waterdata.usgs.gov/news/061016 Please see https://help.waterdata.usgs.gov/news/December%205%2C%202016
for more information.") for more information.")
} }
...@@ -27,33 +27,47 @@ ...@@ -27,33 +27,47 @@
#' } #' }
getWebServiceData <- function(obs_url, ...){ getWebServiceData <- function(obs_url, ...){
returnedList <- RETRY("GET",obs_url, ..., user_agent(default_ua())) returnedList <- tryCatch({
RETRY("GET",obs_url, ..., user_agent(default_ua()))
}, error = function(e){
NULL
})
if(is.null(returnedList)){
message("Switching from https to http")
obs_url <- gsub("https", "http", obs_url)
returnedList <- tryCatch({
RETRY("GET",obs_url, ..., user_agent(default_ua()))
}, error = function(e){
NULL
})
}
if(status_code(returnedList) != 200){ if(status_code(returnedList) != 200){
message("For: ", obs_url,"\n") message("For: ", obs_url,"\n")
stop_for_status(returnedList) stop_for_status(returnedList)
} else { } else {
headerInfo <- headers(returnedList) headerInfo <- headers(returnedList)
if(headerInfo$`content-type` == "text/tab-separated-values;charset=UTF-8"){ if(headerInfo$`content-type` == "text/tab-separated-values;charset=UTF-8"){
returnedDoc <- content(returnedList, type="text",encoding = "UTF-8") returnedDoc <- content(returnedList, type="text",encoding = "UTF-8")
} else if (headerInfo$`content-type` == "text/html"){ } else if (headerInfo$`content-type` == "text/html"){
txt <- readBin(returnedList$content, character()) txt <- readBin(returnedList$content, character())
message(txt) message(txt)
return(txt) return(txt)
} else { } else {
returnedDoc <- content(returnedList,encoding = "UTF-8") returnedDoc <- content(returnedList,encoding = "UTF-8")
if(grepl("No sites/data found using the selection criteria specified", returnedDoc)){ if(grepl("No sites/data found using the selection criteria specified", returnedDoc)){
message(returnedDoc) message(returnedDoc)
}
} }
}
attr(returnedDoc, "headerInfo") <- headerInfo attr(returnedDoc, "headerInfo") <- headerInfo
return(returnedDoc) return(returnedDoc)
} }
} }
default_ua <- function() { default_ua <- function() {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#' Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles", #' Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla" #' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"
#' @return retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for #' @return retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for
#' start and end times, and converted to UTC. See \url{https://www.waterqualitydata.us/portal_userguide.jsp} for more information. #' start and end times, and converted to UTC. See \url{http://www.waterqualitydata.us/portal_userguide/} for more information.
#' @export #' @export
#' @seealso \code{\link{readWQPdata}}, \code{\link{readWQPqw}}, \code{\link{whatWQPsites}} #' @seealso \code{\link{readWQPdata}}, \code{\link{readWQPqw}}, \code{\link{whatWQPsites}}
#' @import utils #' @import utils
......
...@@ -40,15 +40,15 @@ access = match.arg(access, c('public','internal','cooperator','USGS')) ...@@ -40,15 +40,15 @@ access = match.arg(access, c('public','internal','cooperator','USGS'))
message('setting access to public') message('setting access to public')
} }
pkg.env$site = "http://waterservices.usgs.gov/nwis/site/" pkg.env$site = "https://waterservices.usgs.gov/nwis/site/"
pkg.env$iv = "http://waterservices.usgs.gov/nwis/iv/" pkg.env$iv = "https://waterservices.usgs.gov/nwis/iv/"
pkg.env$dv = "http://waterservices.usgs.gov/nwis/dv/" pkg.env$dv = "https://waterservices.usgs.gov/nwis/dv/"
pkg.env$gwlevels = "http://waterservices.usgs.gov/nwis/gwlevels/" pkg.env$gwlevels = "https://waterservices.usgs.gov/nwis/gwlevels/"
pkg.env$measurements = "http://waterdata.usgs.gov/nwis/measurements/" pkg.env$measurements = "https://waterdata.usgs.gov/nwis/measurements/"
pkg.env$peak = "http://nwis.waterdata.usgs.gov/usa/nwis/peak/" pkg.env$peak = "https://nwis.waterdata.usgs.gov/usa/nwis/peak/"
pkg.env$rating = "http://waterdata.usgs.gov/nwisweb/get_ratings/" pkg.env$rating = "https://waterdata.usgs.gov/nwisweb/get_ratings/"
pkg.env$qwdata = "http://nwis.waterdata.usgs.gov/nwis/qwdata" pkg.env$qwdata = "https://nwis.waterdata.usgs.gov/nwis/qwdata"
pkg.env$stat = "http://waterservices.usgs.gov/nwis/stat/" pkg.env$stat = "https://waterservices.usgs.gov/nwis/stat/"
options(Access.dataRetrieval = access) options(Access.dataRetrieval = access)
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
============= =============
Retrieval functions for USGS and EPA hydrologic and water quality data. For tutorial information, see: Retrieval functions for USGS and EPA hydrologic and water quality data. For tutorial information, see:
[http://owi.usgs.gov/R/dataRetrieval.html](http://owi.usgs.gov/R/dataRetrieval.html) [https://owi.usgs.gov/R/dataRetrieval.html](https://owi.usgs.gov/R/dataRetrieval.html)
##Package Installation ##Package Installation
To install the dataRetrieval package, you must be using R 3.0 or greater and run the following command: To install the dataRetrieval package, you must be using R 3.0 or greater and run the following command:
...@@ -13,7 +13,7 @@ install.packages("dataRetrieval") ...@@ -13,7 +13,7 @@ install.packages("dataRetrieval")
To get inter-CRAN release updates, use the command: To get inter-CRAN release updates, use the command:
```r ```r
install.packages("dataRetrieval",repos="http://owi.usgs.gov/R") install.packages("dataRetrieval",repos="https://owi.usgs.gov/R")
``` ```
To get cutting-edge changes, install from GitHub using the `devtools` packages: To get cutting-edge changes, install from GitHub using the `devtools` packages:
...@@ -49,7 +49,7 @@ Follow `@USGS-R` on Twitter for updates on all USGS R packages: ...@@ -49,7 +49,7 @@ Follow `@USGS-R` on Twitter for updates on all USGS R packages:
##Disclaimer ##Disclaimer
This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the [official USGS copyright policy](http://www.usgs.gov/visual-id/credit_usgs.html#copyright/ "official USGS copyright policy") This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the [official USGS copyright policy](https://www.usgs.gov/visual-id/credit_usgs.html#copyright/ "official USGS copyright policy")
Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith. Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.
......
...@@ -18,7 +18,7 @@ Possible values to provide are "America/New_York","America/Chicago", "America/De ...@@ -18,7 +18,7 @@ Possible values to provide are "America/New_York","America/Chicago", "America/De
} }
\value{ \value{
retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for retval dataframe raw data returned from the Water Quality Portal. Additionally, a POSIXct dateTime column is supplied for
start and end times, and converted to UTC. See \url{https://www.waterqualitydata.us/portal_userguide.jsp} for more information. start and end times, and converted to UTC. See \url{http://www.waterqualitydata.us/portal_userguide/} for more information.
} }
\description{ \description{
Imports data from the Water Quality Portal based on a specified url. Imports data from the Water Quality Portal based on a specified url.
......
...@@ -123,11 +123,12 @@ test_that("External importWaterML1 test", { ...@@ -123,11 +123,12 @@ test_that("External importWaterML1 test", {
#raw XML #raw XML
url <- constructNWISURL(service = 'dv', siteNumber = '02319300', parameterCd = "00060", url <- constructNWISURL(service = 'dv', siteNumber = '02319300', parameterCd = "00060",
startDate = "2014-01-01", endDate = "2014-01-01") startDate = "2014-01-01", endDate = "2014-01-01")
raw <- content(GET(url), as = 'raw') # Will put back when https is converted:
rawParsed <- importWaterML1(raw) # raw <- content(GET(url), as = 'raw')
expect_true(nrow(rawParsed) > 0) # rawParsed <- importWaterML1(raw)
expect_true(data.class(rawParsed$X_00060_00003) == "numeric") # expect_true(nrow(rawParsed) > 0)
# expect_true(data.class(rawParsed$X_00060_00003) == "numeric")
#
#no data #no data
url <- constructNWISURL("05212700", "00060", "2014-01-01", "2014-01-10",'dv', statCd = "00001") url <- constructNWISURL("05212700", "00060", "2014-01-01", "2014-01-10",'dv', statCd = "00001")
noData <- importWaterML1(url) noData <- importWaterML1(url)
......
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