Skip to content

Commit

Permalink
fix #171 bump patch version
Browse files Browse the repository at this point in the history
changed all functions to use rappdirs instead of writing to users home dir
cleaned up some code too in terms of line length and prettiness
- storm_data now giving back a tibble instead of a data.frame within a list
  • Loading branch information
sckott committed Oct 6, 2016
1 parent c7b19a2 commit 755be9e
Show file tree
Hide file tree
Showing 29 changed files with 506 additions and 286 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Client for many 'NOAA' data sources including the 'NCDC' climate
for 'NOAA' sea ice data, the 'NOAA' severe weather inventory, 'NOAA' Historical
Observing 'Metadata' Repository ('HOMR') data, 'NOAA' storm data via 'IBTrACS',
tornado data via the 'NOAA' storm prediction center, and more.
Version: 0.6.1.9145
Version: 0.6.3.9100
License: MIT + file LICENSE
Encoding: UTF-8
Authors@R: c(
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ S3method(autoplot,meteo_coverage)
S3method(ncdc_plot,default)
S3method(ncdc_plot,ncdc_data)
S3method(print,buoy)
S3method(print,storm_data)
S3method(print,storm_shp)
S3method(type_summ,Date)
S3method(type_summ,POSIXt)
Expand Down
24 changes: 24 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
rnoaa 0.6.4
===========

### NEW FEATURES

* xxx (#xxx)
* xxx (#xxx)
* xxx (#xxx)

### MINOR IMPROVEMENTS

* `storm_data()` now returns a tibble/data.frame not inside of a list. We used
to return a list with a single slot `data` with a data.frame, but this was
unnecessary.
* xxx (#xxx)
* xxx (#xxx)

### BUG FIXES

* xxx (#xxx)
* xxx (#xxx)
* xxx (#xxx)


rnoaa 0.6.0
===============

Expand Down
26 changes: 17 additions & 9 deletions R/argo.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#' @name argo
#' @template argo_params
#' @template argo_egs
argo_search <- function(func = NULL, of = NULL, qwmo = NULL, wmo = NULL, box=NULL,
area = NULL, around = NULL, year = NULL, yearmin = NULL,
yearmax = NULL, month = NULL, monthmin = NULL, monthmax = NULL,
lr = NULL, from =NULL, to = NULL, dmode = NULL,
pres_qc = NULL, temp_qc = NULL, psal_qc = NULL, doxy_qc = NULL,
argo_search <- function(func = NULL, of = NULL, qwmo = NULL, wmo = NULL, box=NULL,
area = NULL, around = NULL, year = NULL, yearmin = NULL,
yearmax = NULL, month = NULL, monthmin = NULL, monthmax = NULL,
lr = NULL, from =NULL, to = NULL, dmode = NULL,
pres_qc = NULL, temp_qc = NULL, psal_qc = NULL, doxy_qc = NULL,
ticket = NULL, limit = 10, ...) {

if (!is.null(box)) box <- paste0(box, collapse = ",")
args <- noaa_compact(list(get = func, of = of, qwmo = qwmo, wmo = wmo,
box = box, area = area, around = around, year = year, yearmin = yearmin,
box = box, area = area, around = around, year = year, yearmin = yearmin,
yearmax = yearmax, month = month, monthmin = monthmin, monthmax = monthmax,
lr = lr, from = from, to = to, dmode = dmode, pres_qc = pres_qc, temp_qc = temp_qc,
lr = lr, from = from, to = to, dmode = dmode, pres_qc = pres_qc, temp_qc = temp_qc,
psal_qc = psal_qc, doxy_qc = doxy_qc, ticket = ticket, limit = limit))
res <- argo_GET(url = argo_api(), args, ...)
jsonlite::fromJSON(utcf8(res))
Expand Down Expand Up @@ -58,7 +58,15 @@ argo_buoy_files <- function(dac, id, ...) {

#' @export
#' @rdname argo
argo <- function(dac, id, cycle, dtype, path = "~/.rnoaa/argo", overwrite = TRUE, ...) {
argo <- function(dac, id, cycle, dtype, overwrite = TRUE, ...) {
calls <- names(sapply(match.call(), deparse))[-1]
calls_vec <- "path" %in% calls
if (any(calls_vec)) {
stop("The parameter path has been removed, see docs for ?argo",
call. = FALSE)
}

path <- file.path(rnoaa_cache_dir, "argo")
path <- file.path(path, dac)
apath <- a_local(dac, id, cycle, dtype, path)
if (!is_isd(apath)) {
Expand Down
21 changes: 18 additions & 3 deletions R/caching.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
#' Clear cached files
#'
#' @name caching
#' @param path Path to location of cached files. Defaults to \code{disk()$path}
#' @param force (logical) Should we force removal of files if permissions say otherwise?
#' @param force (logical) Should we force removal of files if permissions
#' say otherwise?. Default: \code{FALSE}
#'
#' @details BEWARE: this will clear all cached files.
#'
#' @section File storage:
#' We use \pkg{rappdirs} to store files, see
#' \code{\link[rappdirs]{user_cache_dir}} for how
#' we determine the directory on your machine to save files to, and run
#' \code{user_cache_dir("rnoaa")} to get that directory.

#' @export
#' @rdname caching
ghcnd_clear_cache <- function(path = "~/.rnoaa/ghcnd", force = FALSE) {
ghcnd_clear_cache <- function(force = FALSE) {
calls <- names(sapply(match.call(), deparse))[-1]
calls_vec <- "path" %in% calls
if (any(calls_vec)) {
stop("The parameter path has been removed, see ?ghcnd_clear_cache",
call. = FALSE)
}

path <- file.path(rnoaa_cache_dir, "ghcnd")
files <- list.files(path, full.names = TRUE)
unlink(files, recursive = TRUE, force = force)
}
49 changes: 31 additions & 18 deletions R/ersst.R
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#' NOAA Extended Reconstructed Sea Surface Temperature (ERSST) data
#'
#' @export
#' @param year (numeric) A year. Must be > 1853. The max value is whatever
#' @param year (numeric) A year. Must be > 1853. The max value is whatever
#' the current year is. Required
#' @param month A month, character or numeric. If single digit (e.g. 8), we
#' add a zero in front (e.g., 08). Required
#' @param path (character) A path to store the files, a directory. Default:
#' \code{~/.rnoaa/ersst}. Required.
#' @param overwrite (logical) To overwrite the path to store files in or not,
#' Default: \code{TRUE}
#' @param ... Curl options passed on to \code{\link[httr]{GET}}. Optional
#'
#' @return An \code{ncdf4} object for now, may change output later to
#' perhaps a data.frame. See \pkg{ncdf4} for parsing the output.
#' @references
#' @references
#' \url{https://www.ncdc.noaa.gov/data-access/marineocean-data/extended-reconstructed-sea-surface-temperature-ersst-v4}
#' @details NetCDF files are downloaded, stored, and read from the directory given in the
#' \code{path} parameter. The default is \code{~/.rnoaa/ersst}, and files are
#' saved within whatever that directory is.
#'
#' Files are quite small, so we don't worry about reading in cached data to
#' save time, as we do in other functions in this package.
#'
#' @section File storage:
#' We use \pkg{rappdirs} to store files, see
#' \code{\link[rappdirs]{user_cache_dir}} for how we determine the directory on
#' your machine to save files to, and run \code{user_cache_dir("rnoaa")}
#' to get that directory.
#'
#' Files are quite small, so we don't worry about reading in cached data to
#' save time, as we do in some of the other functions in this package.
#' @examples \dontrun{
#' # October, 2015
#' ersst(year = 2015, month = 10)
#'
#'
#' # May, 2015
#' ersst(year = 2015, month = 5)
#' ersst(year = 2015, month = "05")
#'
#'
#' # February, 1890
#' ersst(year = 1890, month = 2)
#'
#'
#' # Process data
#' library("ncdf4")
#' res <- ersst(year = 1890, month = 2)
Expand All @@ -43,8 +45,15 @@
#' library('httr')
#' ersst(year = 2015, month = 10, config=verbose())
#' }
ersst <- function(year, month, path = "~/.rnoaa/ersst", overwrite = TRUE, ...) {
ersst <- function(year, month, overwrite = TRUE, ...) {
calls <- names(sapply(match.call(), deparse))[-1]
calls_vec <- "path" %in% calls
if (any(calls_vec)) {
stop("The parameter path has been removed, see docs for ?ersst",
call. = FALSE)
}
check4pkg("ncdf4")
path <- file.path(rnoaa_cache_dir, "ersst")
ff <- ersst_local(path, year, month)
dpath <- ersst_GET(make_ersst(year, month), path = ff, overwrite, ...)
ncdf4::nc_open(dpath)
Expand All @@ -57,7 +66,8 @@ make_ersst <- function(year, month) {
}

ersst_base <- function(ver = "v4") {
sprintf("http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/%s/netcdf/ersst.%s", ver, ver)
sprintf("http://www1.ncdc.noaa.gov/pub/data/cmb/ersst/%s/netcdf/ersst.%s",
ver, ver)
}

check_year <- function(x) {
Expand All @@ -66,14 +76,17 @@ check_year <- function(x) {
}

check_month <- function(x) {
if (!nchar(x) %in% c(1, 2)) stop("month must be a length 1 or 2 month value", call. = FALSE)
if (as.numeric(x) < 1 || as.numeric(x) > 12) stop("month must be a number between 1 and 12", call. = FALSE)
if (!nchar(x) %in% c(1, 2))
stop("month must be a length 1 or 2 month value", call. = FALSE)
if (as.numeric(x) < 1 || as.numeric(x) > 12)
stop("month must be a number between 1 and 12", call. = FALSE)
if (nchar(x) == 1) paste0("0", x) else x
}

ersst_GET <- function(dat, path, overwrite, ...) {
dir.create(dirname(path), showWarnings = FALSE, recursive = TRUE)
res <- GET(paste0(ersst_base(), dat), write_disk(path, overwrite = overwrite), ...)
res <- GET(paste0(ersst_base(), dat),
write_disk(path, overwrite = overwrite), ...)
stop_for_status(res)
res$request$output$path
}
Expand Down
Loading

0 comments on commit 755be9e

Please sign in to comment.