Skip to content

Commit

Permalink
fix #331 added cache_mssg internal fxn for handling caching messages
Browse files Browse the repository at this point in the history
and added rnoaa_options() exported fxn to manage whether cache messages are thrown or not

fix #164 ghcnd_stations() now caching files; and caching rds alrady parsed data.frame - big speed up

fix #346 rnoaa_caching manual file with all caching objects

fix #347 transitioned all (i think) data sources to using hoardr objects for caching
  • Loading branch information
sckott committed Mar 24, 2020
1 parent 23b37bd commit bd97af8
Show file tree
Hide file tree
Showing 27 changed files with 294 additions and 326 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.9.5.97
Version: 0.9.5.98
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-US
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export(erddap_info)
export(erddap_search)
export(erddap_table)
export(ersst)
export(ersst_cache)
export(gefs)
export(gefs_dimension_values)
export(gefs_dimensions)
Expand All @@ -48,6 +49,7 @@ export(gefs_longitudes)
export(gefs_times)
export(gefs_variables)
export(ghcnd)
export(ghcnd_cache)
export(ghcnd_clear_cache)
export(ghcnd_countries)
export(ghcnd_read)
Expand Down Expand Up @@ -118,8 +120,10 @@ export(storm_data)
export(storm_meta)
export(storm_shp)
export(storm_shp_read)
export(storms_cache)
export(swdi)
export(theme_ice)
export(torn_cache)
export(tornadoes)
export(type_summ)
export(vis_miss)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
rnoaa 0.9.6
===========

### MINOR IMPROVEMENTS

* remove internal code in many exported functions looking for user input `path` parameter and telling them it's no longer used; been defunct for quite a while


rnoaa 0.9.5
===========

Expand Down
28 changes: 0 additions & 28 deletions R/caching.R

This file was deleted.

10 changes: 10 additions & 0 deletions R/defunct.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ gefs_times <- function(...) {
gefs_variables <- function(...) {
.Defunct(msg = "`gefs_variables` is defunct; it may return later")
}
#' This function is defunct.
#' @export
#' @rdname ghcnd_clear_cache-defunct
#' @keywords internal
ghcnd_clear_cache <- function(...) {
.Defunct(msg = "`ghcnd_clear_cache` is defunct; see ?rnoaa_caching")
}


#' Defunct functions in rnoaa
#'
Expand Down Expand Up @@ -272,6 +280,8 @@ gefs_variables <- function(...) {
#' \item \code{\link{seaice}}: Replaced with \code{\link{sea_ice}}
#' \item \code{\link{lcd_cleanup}}: No longer available. See \code{\link{lcd}}
#' docs
#' \item \code{\link{ghcnd_clear_cache}}: No longer available.
#' See \code{\link{rnoaa_caching}}
#' }
#'
#' The functions for working with GEFS ensemble forecast data (prefixed with
Expand Down
39 changes: 14 additions & 25 deletions R/ersst.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@
#' perhaps a data.frame. See \pkg{ncdf4} for parsing the output.
#' @references
#' <https://www.ncdc.noaa.gov/data-access/marineocean-data/extended-reconstructed-sea-surface-temperature-ersst-v4>
#'
#' @section File storage:
#' We use \pkg{rappdirs} to store files, see
#' [rappdirs::user_cache_dir()] for how we determine the directory on
#' your machine to save files to, and run
#' `rappdirs::user_cache_dir("rnoaa/ersst")`
#' 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.
#' @note See [ersst_cache] for managing cached files
#' @examples \dontrun{
#' # October, 2015
#' ersst(year = 2015, month = 10)
Expand All @@ -44,15 +35,8 @@
#' ncdf4::ncvar_get(res, "ssta")
#' }
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)
ff <- ersst_local(year, month)
dpath <- ersst_GET(make_ersst(year, month), path = ff, overwrite, ...)
ncdf4::nc_open(dpath)
}
Expand Down Expand Up @@ -82,13 +66,18 @@ check_month <- function(x) {
}

ersst_GET <- function(dat, path, overwrite, ...) {
dir.create(dirname(path), showWarnings = FALSE, recursive = TRUE)
cli <- crul::HttpClient$new(paste0(ersst_base(), dat), opts = list(...))
res <- cli$get(disk = path)
res$raise_for_status()
res$content
ersst_cache$mkdir()
if (!file.exists(path)) {
cli <- crul::HttpClient$new(paste0(ersst_base(), dat), opts = list(...))
res <- cli$get(disk = path)
res$raise_for_status()
res$content
} else {
cache_mssg(path)
return(path)
}
}

ersst_local <- function(path, year, month) {
file.path(path, sprintf("%s%s.nc", year, month))
ersst_local <- function(year, month) {
file.path(ersst_cache$cache_path_get(), sprintf("%s%s.nc", year, month))
}
Loading

0 comments on commit bd97af8

Please sign in to comment.