Skip to content
Permalink
Browse files

Fix timeout error, update documentation

Set timeout to 300 sections, reset to default 60 on function exit to
deal with server timeout errors. Add new library to dependencies,
settings, to do this.

Update documentation regarding stations data frame.
  • Loading branch information
adamhsparks committed Jul 1, 2016
1 parent 81d2c8e commit a126641e00dc7acc21844ff0436e5702f8b6e04a
Showing with 13 additions and 11 deletions.
  1. +1 −0 DESCRIPTION
  2. +3 −4 R/data.R
  3. +7 −4 R/get_GSOD.R
  4. +2 −3 man/stations.Rd
@@ -56,6 +56,7 @@ Imports:
lubridate,
raster,
readr,
settings,
sp,
stats,
stringr,
@@ -1,5 +1,5 @@
#' GSOD Station Data
#'
#'
#' Station information for the US National Climatic Data Centre (NCDC)
#' Global Surface Summary of the Day (GSOD) weather data. The original file has
#' missing and incorrect information. This is a clean version of this dataset,
@@ -25,9 +25,8 @@
#' Re-distribution of these data by others must provide this same
#' notification."}
#'
#' To access this data frame of station information, use
#' \code{\link[utils]{data}("stations")} to load it into the global environment
#' for inspection or use by the user.
#' The data are automatically loaded with the package, to see the stations, type
#' \code{stations}
#'
#' @format A data frame with 27699 observations of 12 variables:
#' \describe{
@@ -206,7 +206,8 @@ get_GSOD <- function(years = NULL, station = NULL, country = NULL, path = "",
shapefile = FALSE, CSV = TRUE) {

# Setting up options, creating objects, check variables entered by user-------
options(warn = 2)

opt <- settings::options_manager(warn = 2, timeout = 300)

utils::data("stations", package = "GSODR", envir = environment())
stations <- get("stations", envir = environment())
@@ -279,7 +280,8 @@ get_GSOD <- function(years = NULL, station = NULL, country = NULL, path = "",

# If a single station is selected---------------------- --------------------
if (!is.null(station)) {
tmp <- .read_gz(paste0(ftp_site, yr, "/", station, "-", yr, ".op.gz"))
tmp <- try(.read_gz(paste0(ftp_site, yr, "/", station, "-", yr,
".op.gz")))
GSOD_XY <- .reformat(tmp, stations)
} else {
# For a country, the entire set or agroclimatology -----------------------
@@ -368,9 +370,9 @@ get_GSOD <- function(years = NULL, station = NULL, country = NULL, path = "",
tmp$YDAY <- lubridate::yday(as.Date(paste(tmp$YEAR, tmp$MONTH, tmp$DAY,
sep = "-")))

tmp$TEMP <- ifelse(!is.na(tmp$TEMP), round( ( (5 / 9) * (tmp$TEMP - 32)), 1),
tmp$TEMP <- ifelse(!is.na(tmp$TEMP), round( ((5 / 9) * (tmp$TEMP - 32)), 1),
NA_integer_)
tmp$DEWP <- ifelse(!is.na(tmp$DEWP), round( ( (5 / 9) * (tmp$DEWP - 32)), 1),
tmp$DEWP <- ifelse(!is.na(tmp$DEWP), round( ((5 / 9) * (tmp$DEWP - 32)), 1),
NA_integer_)
tmp$WDSP <- ifelse(!is.na(tmp$WDSP), round(tmp$WDSP * 0.514444444, 1),
NA_integer_)
@@ -420,6 +422,7 @@ get_GSOD <- function(years = NULL, station = NULL, country = NULL, path = "",
"I.THUNDER", "I.TDO_FNL",
"EA", "ES", "RH")]
return(GSOD_df)
settings::reset(opt)
}

.read_gz <- function(gz_file) {

Some generated files are not rendered by default. Learn more.

0 comments on commit a126641

Please sign in to comment.
You can’t perform that action at this time.