-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using hoardr for cache path setup, rework pg_data to use hoardr object
- Loading branch information
Showing
12 changed files
with
176 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,45 @@ | ||
env <- new.env(parent = emptyenv()) | ||
|
||
.onLoad <- function(libname, pkgname) { | ||
path <- rappdirs::user_cache_dir("pangaear") | ||
env$path <- path | ||
} | ||
#' @title Caching | ||
#' | ||
#' @description Manage cached `pangaear` files with \pkg{hoardr} | ||
#' | ||
#' @export | ||
#' @name pg_cache | ||
#' | ||
#' @details The dafault cache directory is | ||
#' `paste0(rappdirs::user_cache_dir(), "/R/pangaear")`, but you can set | ||
#' your own path using `cache_path_set()` | ||
#' | ||
#' `cache_delete` only accepts 1 file name, while | ||
#' `cache_delete_all` doesn't accept any names, but deletes all files. | ||
#' For deleting many specific files, use `cache_delete` in a [lapply()] | ||
#' type call | ||
#' | ||
#' @section Useful user functions: | ||
#' \itemize{ | ||
#' \item `pg_cache$cache_path_get()` get cache path | ||
#' \item `pg_cache$cache_path_set()` set cache path | ||
#' \item `pg_cache$list()` returns a character vector of full | ||
#' path file names | ||
#' \item `pg_cache$files()` returns file objects with metadata | ||
#' \item `pg_cache$details()` returns files with details | ||
#' \item `pg_cache$delete()` delete specific files | ||
#' \item `pg_cache$delete_all()` delete all files, returns nothing | ||
#' } | ||
#' | ||
#' @examples \dontrun{ | ||
#' pg_cache | ||
#' | ||
#' # list files in cache | ||
#' pg_cache$list() | ||
#' | ||
#' # delete certain database files | ||
#' # pg_cache$delete("file path") | ||
#' # pg_cache$list() | ||
#' | ||
#' # delete all files in cache | ||
#' # pg_cache$delete_all() | ||
#' # pg_cache$list() | ||
#' | ||
#' # set a different cache path from the default | ||
#' } | ||
NULL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# env <- new.env(parent = emptyenv()) | ||
pg_cache <- NULL # nocov start | ||
|
||
.onLoad <- function(libname, pkgname) { | ||
x <- hoardr::hoard() | ||
x$cache_path_set("pangaear") | ||
pg_cache <<- x | ||
} # nocov start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,13 @@ | ||
#' cache path clear | ||
#' @export | ||
#' @rdname pg_data | ||
pg_cache_clear <- function(doi = NULL, prompt = TRUE) { | ||
if (is.null(doi)) { | ||
files <- list.files(env$path, full.names = TRUE) | ||
resp <- if (prompt) { | ||
readline(sprintf("Sure you want to clear all %s files? [y/n]: ", | ||
length(files))) | ||
} else { | ||
"y" | ||
} | ||
if (resp == "y") unlink(files, force = TRUE) else NULL | ||
} else { | ||
files <- file.path(env$path, rdoi(doi)) | ||
unlink(files, force = TRUE) | ||
} | ||
#' @rdname pg_cache_clear-defunct | ||
#' @param ... ignored | ||
pg_cache_clear <- function(...) { | ||
.Defunct(msg = "defunct, see pg_cache$delete() and pg_cache$delete_all()") | ||
} | ||
|
||
#' cache list | ||
#' @export | ||
#' @rdname pg_data | ||
pg_cache_list <- function() list.files(env$path) | ||
#' @rdname pg_cache_list-defunct | ||
#' @param ... ignored | ||
pg_cache_list <- function(...) .Defunct(msg = "defunct, see pg_cache$list()") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.