Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Hid a variety of functions making calls from namespace instead
Browse files Browse the repository at this point in the history
Close issue #16
  • Loading branch information
emhart committed Dec 13, 2013
1 parent f87e1b9 commit 68cf05d
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion R/check_ISO_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#'check_ISO_code("USA")
#'}
#'
#'@export



check_ISO_code <- function(iso){
Expand Down
2 changes: 1 addition & 1 deletion R/check_locator.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Checks for what kind of locator a user input
#' @param locator The ISO3 country code that you want data about. (http://unstats.un.org/unsd/methods/m49/m49alpha.htm) or the basin ID [1-468]
#' @return geo_ref a string indicating what kind of geography to use in the api
#'@export


check_locator <- function(locator){

Expand Down
2 changes: 1 addition & 1 deletion R/create_map_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ create_map_df <- function(locator,resolution = .007){
### All error handling is done in the download_kml()
locator <- as.character(locator)
locator <- toupper(locator)
download_kml(locator,resolution)
rWBclimate:::download_kml(locator,resolution)


my_path <- path.expand(getOption("kmlpath"))
Expand Down
3 changes: 0 additions & 3 deletions R/download_kml.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#' @param resolution The optional simplification value is a decimal value between 0 and 1 that specifies boundary resolution; 0 (the default) is the highest available resolution while 1 is the lowest. This option lets you request simpler and thus smaller boundaries at the expense of resolution. A value of 0.01 reduces output and complexity by roughly 50%; values above 0.05 begin to lose too much detail.
#' @details kml files can be quite large making downloading them every time you want to make a map time consuming. To
#' reduce this time it's easiest to download kml files and store them. To set the directory use a line like this: \code{options(kmlpath="/Users/emh/kmltemp")} The option must be called "kmlpath".
#'
#' @export

download_kml <- function(locator, resolution = .007){
if(is.null(getOption("kmlpath"))){stop("You must first set the kmlpath parameter in options, see help for details.")}
#get vector of file names.
Expand Down
4 changes: 1 addition & 3 deletions R/get_climate_data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#'Download climate data
#'
#'@description Download monthly average climate data from the world bank climate
#' data api. Ideally you'll want to use the wrapper functions that call this.
Expand All @@ -10,15 +9,14 @@
#' @param cvar The variable you're interested in. "pr" for precipitation, "tas" for temperature in celcius.
#' @param start The starting year you want data for, can be in the past or the future. Must conform to the periods outlined in the world bank API. If given values don't conform to dates, the fuction will automatically round them.
#' @param end The ending year you want data for, can be in the past or the future. Similar to the start date, dates will be rounded to the nearest end dat.
#' @export
#'

get_climate_data <- function(locator,geo_type,type, cvar, start, end){
base_url <- "http://climatedataapi.worldbank.org/climateweb/rest/v1/"

### Error handling
if(geo_type == "country"){
check_ISO_code(locator)
rWBclimate:::check_ISO_code(locator)
}

if(geo_type == "basin"){
Expand Down
2 changes: 1 addition & 1 deletion R/get_data_recursive.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


get_data_recursive <- function(locator,geo_type,type, cvar, start, end){
dates <- date_correct(start,end)
dates <- rWBclimate:::date_correct(start,end)
data_out <- list()
counter <- 1
for(i in 1:length(locator)){
Expand Down
3 changes: 1 addition & 2 deletions R/get_ensemble_climate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
#' @param cvar The variable you're interested in. "pr" for precipitation, "tas" for temperature in celcius.
#' @param start The starting year you want data for, can be in the past or the future. Must conform to the periods outlined in the world bank API. If given values don't conform to dates, the fuction will automatically round them.
#' @param end The ending year you want data for, can be in the past or the future. Similar to the start date, dates will be rounded to the nearest end dat.
#' @export


get_ensemble_climate_data <- function(locator,geo_type,type, cvar, start, end){
base_url <- "http://climatedataapi.worldbank.org/climateweb/rest/v1/"

### Error handling
if(geo_type == "country"){
check_ISO_code(locator)
rWBclimate:::check_ISO_code(locator)
}

if(geo_type == "basin"){
Expand Down
6 changes: 3 additions & 3 deletions R/get_ensemble_data_recursive.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#' @examples \dontrun{
#' get_ensemble_data_recursive(c("1","2"),"basin","mavg","pr",1920,1940)
#'}
#'@export



get_ensemble_data_recursive <- function(locator,geo_type,type, cvar, start, end){
dates <- date_correct(start,end)
dates <- rWBclimate:::date_correct(start,end)
data_out <- list()
counter <- 1
for(i in 1:length(locator)){
for(j in 1:length(dates[,1])){
data_out[[counter]] <- get_ensemble_climate_data(locator[i],geo_type,type,cvar,dates[j,1],dates[j,2])
data_out[[counter]] <- rWBclimate:::get_ensemble_climate_data(locator[i],geo_type,type,cvar,dates[j,1],dates[j,2])
counter <- counter + 1
}
}
Expand Down
4 changes: 2 additions & 2 deletions R/get_ensemble_precip.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ get_ensemble_precip <- function(locator,type, start, end){

#Convert numeric basin numbers to strings if they were entered incorrectly
locator <- as.character(locator)
geo_ref <- check_locator(locator)
geo_ref <- rWBclimate:::check_locator(locator)


output <- get_ensemble_data_recursive(locator,geo_ref,type, "pr", start, end)
output <- rWBclimate:::get_ensemble_data_recursive(locator,geo_ref,type, "pr", start, end)
return(output)
}
4 changes: 2 additions & 2 deletions R/get_ensemble_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_ensemble_stats <- function(locator,type,stat){
locator <- as.character(locator)

## Error handling for location input
geo_ref <- check_locator(locator)
geo_ref <- rWBclimate:::check_locator(locator)


### Set dates to retrieve both future scenarios.
Expand All @@ -59,7 +59,7 @@ get_ensemble_stats <- function(locator,type,stat){
counter <- 1
for(i in 1:length(locator)){
for(j in 1:length(dates[,1])){
data_out[[counter]] <- get_ensemble_climate_data(locator[i],geo_ref,type,stat,dates[j,1],dates[j,2])
data_out[[counter]] <- rWBclimate:::get_ensemble_climate_data(locator[i],geo_ref,type,stat,dates[j,1],dates[j,2])
counter <- counter + 1
}
}
Expand Down
5 changes: 3 additions & 2 deletions R/get_ensemble_temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#'}
#'@export


get_ensemble_temp <- function(locator,type, start, end){
### check type is valid
typevec <- c("mavg","annualavg","manom","annualanom")
Expand All @@ -44,9 +45,9 @@ get_ensemble_temp <- function(locator,type, start, end){
}
#Convert numeric basin numbers to strings if they were entered incorrectly
locator <- as.character(locator)
geo_ref <- check_locator(locator)
geo_ref <- rWBclimate:::check_locator(locator)

output <- get_ensemble_data_recursive(locator,geo_ref,type, "tas", start, end)
output <- rWBclimate:::get_ensemble_data_recursive(locator,geo_ref,type, "tas", start, end)
return(output)
}

6 changes: 3 additions & 3 deletions R/get_historical_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#' @examples \dontrun{
#'
#' }
#' @export


get_historical_data <- function(locator,cvar,time_scale){
base_url <- "http://climatedataapi.worldbank.org/climateweb/rest/v1/"
Expand All @@ -34,11 +34,11 @@ if(!time_scale%in%time_vec){
}
#Convert numeric basin numbers to strings if they were entered incorrectly
locator <- as.character(locator)
geo_type <- check_locator(locator)
geo_type <- rWBclimate:::check_locator(locator)

### Error handling
if(geo_type == "country"){
check_ISO_code(locator)
rWBclimate:::check_ISO_code(locator)
}

if(geo_type == "basin"){
Expand Down
4 changes: 2 additions & 2 deletions R/get_historical_data_recursive.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#' @examples \dontrun{
#'
#' }
#' @export

get_historical_data_recursive <- function(locator,cvar,time_scale){
data_out <- list()
counter <- 1
for(i in 1:length(locator)){
data_out[[i]] <- get_historical_data(locator[i],cvar,time_scale)
data_out[[i]] <- rWBclimate:::get_historical_data(locator[i],cvar,time_scale)
}

dat_out <- ldply(data_out,data.frame)
Expand Down
2 changes: 1 addition & 1 deletion R/get_historical_precip.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

get_historical_precip <- function(locator,time_scale){
cvar <- "pr"
return(get_historical_data_recursive(locator,cvar,time_scale))
return(rWBclimate:::get_historical_data_recursive(locator,cvar,time_scale))
}
2 changes: 1 addition & 1 deletion R/get_historical_temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@

get_historical_temp <- function(locator,time_scale){
cvar <- "tas"
return(get_historical_data_recursive(locator,cvar,time_scale))
return(rWBclimate:::get_historical_data_recursive(locator,cvar,time_scale))
}
4 changes: 2 additions & 2 deletions R/get_model_precip.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ get_model_precip <- function(locator,type, start, end){
}
#Convert numeric basin numbers to strings if they were entered incorrectly
locator <- as.character(locator)
geo_ref <- check_locator(locator)
geo_ref <- rWBclimate:::check_locator(locator)

output <- get_data_recursive(locator,geo_ref,type, "pr", start, end)
output <- rWBclimate:::get_data_recursive(locator,geo_ref,type, "pr", start, end)
return(output)
}

4 changes: 2 additions & 2 deletions R/get_model_temp.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ get_model_temp <- function(locator,type, start, end){
}
#Convert numeric basin numbers to strings if they were entered incorrectly
locator <- as.character(locator)
geo_ref <- check_locator(locator)
geo_ref <- rWBclimate:::check_locator(locator)

output <- get_data_recursive(locator,geo_ref,type, "tas", start, end)
output <- rWBclimate:::get_data_recursive(locator,geo_ref,type, "tas", start, end)
return(output)
}

0 comments on commit 68cf05d

Please sign in to comment.