From 9345a0dbd9253c6533a2564989cb016a88597805 Mon Sep 17 00:00:00 2001 From: Jordan S Read <jread@usgs.gov> Date: Tue, 10 Nov 2015 08:46:14 -0600 Subject: [PATCH] straw dog for access pattern --- NAMESPACE | 1 + R/AAA.R | 4 ++++ R/setAccess.R | 38 ++++++++++++++++++++++++++++++++++++++ R/whatNWISsites.R | 2 +- man/setAccess.Rd | 29 +++++++++++++++++++++++++++++ man/whatNWISData.Rd | 2 +- 6 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 R/AAA.R create mode 100644 R/setAccess.R create mode 100644 man/setAccess.Rd diff --git a/NAMESPACE b/NAMESPACE index 09a0ba02..8109f841 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ export(readNWISuv) export(readWQPdata) export(readWQPqw) export(renameNWISColumns) +export(setAccess) export(stateCd) export(stateCdLookup) export(whatNWISdata) diff --git a/R/AAA.R b/R/AAA.R new file mode 100644 index 00000000..9eea437b --- /dev/null +++ b/R/AAA.R @@ -0,0 +1,4 @@ +pkg.env <- new.env() +.onLoad = function(libname, pkgname){ + setAccess('public') +} \ No newline at end of file diff --git a/R/setAccess.R b/R/setAccess.R new file mode 100644 index 00000000..7b3762b2 --- /dev/null +++ b/R/setAccess.R @@ -0,0 +1,38 @@ +#'Set data endpoint +#' +#'access Indicate which dataRetrieval access code +#' you want to use options: \code{c('public','internal')} +#' +#' @param access code for data access. Either "public" or "internal" +#' +#'@author Luke Winslow, Jordan S Read +#' +#'@examples +#' +#'\dontrun{ +#'setAccess('internal') +#' +#'setAccess('public') +#' +#'} +#' +#' @export +setAccess = function(access="public"){ + + access = match.arg(access, c('public','internal')) + + if(access=="internal"){ + access.param = '?Access=3' + message('setting access to internal') + }else { + access.param = '?Access=1' + } + + pkg.env$waterservices = paste0("http://waterservices.usgs.gov/nwis/site/", access.param) + + +} + +drURL = function(base.name, params){ + return(paste0(pkg.env[[base.name]], params)) +} \ No newline at end of file diff --git a/R/whatNWISsites.R b/R/whatNWISsites.R index 49e34e84..4ad9d93d 100644 --- a/R/whatNWISsites.R +++ b/R/whatNWISsites.R @@ -40,7 +40,7 @@ whatNWISsites <- function(...){ names(values)[names(values) == "siteNumber"] <- "sites" names(values)[names(values) == "siteNumbers"] <- "sites" - baseURL <- "http://waterservices.usgs.gov/nwis/site/?format=mapper&" + baseURL <- drURL('waterservices',"&format=mapper&") urlCall <- paste(baseURL, urlCall,sep = "") diff --git a/man/setAccess.Rd b/man/setAccess.Rd new file mode 100644 index 00000000..a8a7822c --- /dev/null +++ b/man/setAccess.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/setAccess.R +\name{setAccess} +\alias{setAccess} +\title{Set data endpoint} +\usage{ +setAccess(access = "public") +} +\arguments{ +\item{access}{code for data access. Either "public" or "internal"} +} +\description{ +access Indicate which dataRetrieval access code +you want to use options: \code{c('public','internal')} +} +\examples{ + +\dontrun{ +setAccess('internal') + +setAccess('public') + +} + +} +\author{ +Luke Winslow, Jordan S Read +} + diff --git a/man/whatNWISData.Rd b/man/whatNWISData.Rd index d236dfb6..05bb05be 100644 --- a/man/whatNWISData.Rd +++ b/man/whatNWISData.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/whatNWISdata.r +% Please edit documentation in R/whatNWISData.r \name{whatNWISdata} \alias{whatNWISdata} \title{USGS data availability} -- GitLab