From 4339a8aecdb3872a75607715ecf6b3cdcaa4f326 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Fri, 16 Feb 2018 19:12:17 -0500 Subject: [PATCH 01/15] allow arg-less directory setting to default to current working dir --- R/cacheDirectories.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/cacheDirectories.R b/R/cacheDirectories.R index d07efd3..820227b 100644 --- a/R/cacheDirectories.R +++ b/R/cacheDirectories.R @@ -12,9 +12,7 @@ #' @export #' @example #' R/examples/example.R -setCacheDir = function(cacheDir) { - options(RCACHE.DIR=cacheDir) -} +setCacheDir = function(cacheDir=NULL) { .setDir("RCACHE.DIR", cacheDir) } #' Set shared cache directory #' @@ -24,17 +22,13 @@ setCacheDir = function(cacheDir) { #' #' @param sharedCacheDir Directory where shared caches should be stored #' @export -setSharedCacheDir = function(sharedCacheDir) { - options(RESOURCES.RCACHE=sharedCacheDir) -} +setSharedCacheDir = function(sharedCacheDir=NULL) { .setDir("RESOURCES.RCACHE", sharedCacheDir) } #' Sets local cache build directory with scripts for building files. #' #' @param cacheBuildDir Directory where build scripts are stored. #' @export -setCacheBuildDir = function(cacheBuildDir) { - options(RBUILD.DIR=cacheBuildDir) -} +setCacheBuildDir = function(cacheBuildDir=NULL) { .setDir("RBUILD.DIR", cacheBuildDir) } #' View simpleCache options #' @@ -66,3 +60,9 @@ resetCacheSearchEnvironment = function() { options(SIMPLECACHE.ENV=NULL) } + +.setDir <- function(optname, dirpath=NULL) { + diropts <- list(ifelse(is.null(dirpath), getwd(), dirpath)) + names(diropts) <- optname + do.call(options, diropts) +} From 5a7592dcd717a3196be4542f8cb511aa37783679 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Fri, 16 Feb 2018 19:31:10 -0500 Subject: [PATCH 02/15] add tests --- tests/testthat/test_all.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index 949dc66..413735c 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -2,6 +2,19 @@ library(simpleCache) context("error checking") + +kSetters <- list(RCACHE.DIR=setCacheDir, RESOURCES.RCACHE=setSharedCacheDir, RBUILD.DIR=setCacheBuildDir) + +test_dir_default <- function(cacheDirOptname) { + expect_false(getwd() == getOption(cacheDirOptname)) + test_that(sprintf("%s setter uses current folder for argument-less call", cacheDirOptname), { + do.call(kSetters[[cacheDirOptname]], args=list()) + expect_equal(getwd(), getOption(cacheDirOptname)) + }) + resetCacheSearchEnvironment() +} + + test_that("notifications and messages as expected", { # message if cache exists @@ -123,6 +136,10 @@ test_that("option setting works", { }) + +for (optname in names(kSetters)) { test_dir_default(optname) } + + test_that("objects pass through in buildEnvir", { setCacheDir(tempdir()) From c6385a114736c6f3031a3438a3a34980f42c4511 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Fri, 16 Feb 2018 19:37:47 -0500 Subject: [PATCH 03/15] clean up test and comment --- tests/testthat/test_all.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index 413735c..b1d7604 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -3,10 +3,13 @@ library(simpleCache) context("error checking") +# Map option name to its setter. kSetters <- list(RCACHE.DIR=setCacheDir, RESOURCES.RCACHE=setSharedCacheDir, RBUILD.DIR=setCacheBuildDir) + +# Test a cache dir setting in managed context fashion, resetting before and after test. test_dir_default <- function(cacheDirOptname) { - expect_false(getwd() == getOption(cacheDirOptname)) + resetCacheSearchEnvironment() test_that(sprintf("%s setter uses current folder for argument-less call", cacheDirOptname), { do.call(kSetters[[cacheDirOptname]], args=list()) expect_equal(getwd(), getOption(cacheDirOptname)) @@ -137,6 +140,7 @@ test_that("option setting works", { }) +# Test each cache directory option setter. for (optname in names(kSetters)) { test_dir_default(optname) } From 4517cd3ed40dc168d1ec6e284e5266b5ee6a1067 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Fri, 16 Feb 2018 19:40:00 -0500 Subject: [PATCH 04/15] match to current style --- R/cacheDirectories.R | 6 +++--- tests/testthat/test_all.R | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/cacheDirectories.R b/R/cacheDirectories.R index 820227b..f00c46c 100644 --- a/R/cacheDirectories.R +++ b/R/cacheDirectories.R @@ -61,8 +61,8 @@ resetCacheSearchEnvironment = function() { } -.setDir <- function(optname, dirpath=NULL) { - diropts <- list(ifelse(is.null(dirpath), getwd(), dirpath)) - names(diropts) <- optname +.setDir = function(optname, dirpath=NULL) { + diropts = list(ifelse(is.null(dirpath), getwd(), dirpath)) + names(diropts) = optname do.call(options, diropts) } diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index b1d7604..ffcd119 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -4,11 +4,11 @@ context("error checking") # Map option name to its setter. -kSetters <- list(RCACHE.DIR=setCacheDir, RESOURCES.RCACHE=setSharedCacheDir, RBUILD.DIR=setCacheBuildDir) +kSetters = list(RCACHE.DIR=setCacheDir, RESOURCES.RCACHE=setSharedCacheDir, RBUILD.DIR=setCacheBuildDir) # Test a cache dir setting in managed context fashion, resetting before and after test. -test_dir_default <- function(cacheDirOptname) { +test_dir_default = function(cacheDirOptname) { resetCacheSearchEnvironment() test_that(sprintf("%s setter uses current folder for argument-less call", cacheDirOptname), { do.call(kSetters[[cacheDirOptname]], args=list()) From 5bc2ba79c09412d3c2aa47be8bdacdb375cf4252 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Fri, 13 Apr 2018 09:20:52 -0400 Subject: [PATCH 05/15] only list files that appear to be caches --- R/listCaches.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/listCaches.R b/R/listCaches.R index dff1b03..098b129 100644 --- a/R/listCaches.R +++ b/R/listCaches.R @@ -9,6 +9,7 @@ #' @example #' R/examples/example.R listCaches = function(cacheSubDir="") { - list.files(paste0(getOption("RCACHE.DIR"), cacheSubDir)) + cacheDirFiles = list.files(paste0(getOption("RCACHE.DIR"), cacheSubDir)) + cacheDirFiles[which(sapply(cacheDirFiles, function(f) endsWith(f, ".RData")))] } From 3821d5d6ebdb862d2b76492e49eec79c159ad17d Mon Sep 17 00:00:00 2001 From: nsheff Date: Fri, 8 Jun 2018 13:00:43 -0400 Subject: [PATCH 06/15] Fix bug with missing environment --- DESCRIPTION | 2 +- R/simpleCache.R | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eaedecd..9d3df40 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: simpleCache -Version: 0.4.0 +Version: 0.4.1 Date: 2017-08-21 Title: Simply Caching R Objects Description: Provides intuitive functions for caching R objects, encouraging diff --git a/R/simpleCache.R b/R/simpleCache.R index 6a08f61..be6399a 100755 --- a/R/simpleCache.R +++ b/R/simpleCache.R @@ -134,7 +134,9 @@ simpleCache = function(cacheName, instruction=NULL, buildEnvir=NULL, cacheWhere = NULL for ( curEnv in searchEnvir ) { - if(exists(cacheName, where=get(curEnv))) { + if(!is.environment(curEnv)) { + warning(curEnv, " is not an environment.") + } else if( exists(cacheName, where=get(curEnv))) { cacheExists = TRUE cacheWhere = curEnv break From 09a351915f2a04dd888b8376a99757418ab03781 Mon Sep 17 00:00:00 2001 From: nsheff Date: Fri, 8 Jun 2018 13:33:16 -0400 Subject: [PATCH 07/15] fix missing env --- R/simpleCache.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/simpleCache.R b/R/simpleCache.R index be6399a..c95c2f4 100755 --- a/R/simpleCache.R +++ b/R/simpleCache.R @@ -134,7 +134,7 @@ simpleCache = function(cacheName, instruction=NULL, buildEnvir=NULL, cacheWhere = NULL for ( curEnv in searchEnvir ) { - if(!is.environment(curEnv)) { + if(! ( exists(curEnv) && is.environment(get(curEnv))) ) { warning(curEnv, " is not an environment.") } else if( exists(cacheName, where=get(curEnv))) { cacheExists = TRUE From 873e365acb8483b02f04eb625f4eac653d2862f4 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 24 Oct 2018 15:27:31 -0400 Subject: [PATCH 08/15] first pass at cache dir fetch alias --- R/cacheDirectories.R | 9 +++++++++ tests/testthat/test_all.R | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/R/cacheDirectories.R b/R/cacheDirectories.R index f00c46c..cb21c3c 100644 --- a/R/cacheDirectories.R +++ b/R/cacheDirectories.R @@ -14,6 +14,15 @@ #' R/examples/example.R setCacheDir = function(cacheDir=NULL) { .setDir("RCACHE.DIR", cacheDir) } +#' Fetcher of the currently set cache directory. +#' +#' \code{getCacheDir} retrieves the value of the option that stores the currently +#' set cache directory path. +#' +#' @return If the option is set, the path to the currently set cache directory; otherwise, \code{NULL}. +#' @export +getCacheDir = function() { getOption("RCACHE.DIR") } + #' Set shared cache directory #' #' Sets global variable specifying the default cache directory for diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index ffcd119..3ed304f 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -139,6 +139,12 @@ test_that("option setting works", { }) +test_that("Cache dir fetch works", { + expect_true(is.null(getCacheDir())) + setCacheDir(tempdir()) + expect_false(is.null(getCacheDir())) + expect_equal(getCacheDir(), tempdir()) +}) # Test each cache directory option setter. for (optname in names(kSetters)) { test_dir_default(optname) } From a48b47670847a98f2e9cc6aa20a75c7ef37c4bf0 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 24 Oct 2018 15:28:12 -0400 Subject: [PATCH 09/15] docs build --- DESCRIPTION | 2 +- NAMESPACE | 1 + man/deleteCaches.Rd | 3 ++- man/dot-tooOld.Rd | 28 ++++++++++++++++++++++++++++ man/getCacheDir.Rd | 15 +++++++++++++++ man/setCacheBuildDir.Rd | 2 +- man/setCacheDir.Rd | 2 +- man/setSharedCacheDir.Rd | 2 +- man/simpleCache-package.Rd | 10 ++++++++-- man/simpleCache.Rd | 11 ++++++----- 10 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 man/dot-tooOld.Rd create mode 100644 man/getCacheDir.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 830eaa6..0a0a5c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,4 +22,4 @@ License: BSD_2_clause + file LICENSE Encoding: UTF-8 URL: https://www.github.com/databio/simpleCache BugReports: https://www.github.com/databio/simpleCache -RoxygenNote: 6.0.1.9000 +RoxygenNote: 6.1.0 diff --git a/NAMESPACE b/NAMESPACE index da5de29..3565541 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(addCacheSearchEnvironment) export(deleteCaches) +export(getCacheDir) export(listCaches) export(loadCaches) export(resetCacheSearchEnvironment) diff --git a/man/deleteCaches.Rd b/man/deleteCaches.Rd index 9944dae..61f380f 100644 --- a/man/deleteCaches.Rd +++ b/man/deleteCaches.Rd @@ -4,7 +4,8 @@ \alias{deleteCaches} \title{Deletes caches} \usage{ -deleteCaches(cacheNames, cacheDir = getOption("RCACHE.DIR"), force = FALSE) +deleteCaches(cacheNames, cacheDir = getOption("RCACHE.DIR"), + force = FALSE) } \arguments{ \item{cacheNames}{Name(s) of the cache to delete} diff --git a/man/dot-tooOld.Rd b/man/dot-tooOld.Rd new file mode 100644 index 0000000..8f6091c --- /dev/null +++ b/man/dot-tooOld.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utility.R +\name{.tooOld} +\alias{.tooOld} +\title{Determine if a cache file is sufficiently old to warrant refresh.} +\usage{ +.tooOld(pathCacheFile, lifespan = NULL) +} +\arguments{ +\item{pathCacheFile}{Path to file to ask about staleness.} + +\item{lifespan}{Maximum file age before it's "stale."} +} +\value{ +\code{TRUE} if the file exists and its age exceeds + \code{lifespan} if given or + \code{getOption("MAX.CACHE.AGE")} if no age threshold is passed + and that option exists; \code{FALSE} otherwise. +} +\description{ +\code{.tooOld} accepts a maximum cache age and checks for an option with +that setting under \code{MAX.CACHE.AGE} if such an argument isn't passed. +If the indicated file exists and is older than the threshold passed or +set as an option, the file is deemed "stale." If an age threshold is +provided, no check for an option is performed. If the file does not +exist or there's not an age threshold directly passed or set as an option, +the result is \code{FALSE}. +} diff --git a/man/getCacheDir.Rd b/man/getCacheDir.Rd new file mode 100644 index 0000000..e5e8a36 --- /dev/null +++ b/man/getCacheDir.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cacheDirectories.R +\name{getCacheDir} +\alias{getCacheDir} +\title{Fetcher of the currently set cache directory.} +\usage{ +getCacheDir() +} +\value{ +If the option is set, the path to the currently set cache directory; otherwise, \code{NULL}. +} +\description{ +\code{getCacheDir} retrieves the value of the option that stores the currently +set cache directory path. +} diff --git a/man/setCacheBuildDir.Rd b/man/setCacheBuildDir.Rd index b50004e..a6ff390 100644 --- a/man/setCacheBuildDir.Rd +++ b/man/setCacheBuildDir.Rd @@ -4,7 +4,7 @@ \alias{setCacheBuildDir} \title{Sets local cache build directory with scripts for building files.} \usage{ -setCacheBuildDir(cacheBuildDir) +setCacheBuildDir(cacheBuildDir = NULL) } \arguments{ \item{cacheBuildDir}{Directory where build scripts are stored.} diff --git a/man/setCacheDir.Rd b/man/setCacheDir.Rd index 4c3c969..5d8e820 100644 --- a/man/setCacheDir.Rd +++ b/man/setCacheDir.Rd @@ -5,7 +5,7 @@ \title{Sets a global variable specifying the default cache directory for \code{\link{simpleCache}} calls.} \usage{ -setCacheDir(cacheDir) +setCacheDir(cacheDir = NULL) } \arguments{ \item{cacheDir}{Directory where caches should be stored} diff --git a/man/setSharedCacheDir.Rd b/man/setSharedCacheDir.Rd index 9cdb4df..baef240 100644 --- a/man/setSharedCacheDir.Rd +++ b/man/setSharedCacheDir.Rd @@ -4,7 +4,7 @@ \alias{setSharedCacheDir} \title{Set shared cache directory} \usage{ -setSharedCacheDir(sharedCacheDir) +setSharedCacheDir(sharedCacheDir = NULL) } \arguments{ \item{sharedCacheDir}{Directory where shared caches should be stored} diff --git a/man/simpleCache-package.Rd b/man/simpleCache-package.Rd index 8ffb681..5d34032 100644 --- a/man/simpleCache-package.Rd +++ b/man/simpleCache-package.Rd @@ -7,8 +7,14 @@ \title{Provides intuitive functions for caching R objects, encouraging faster reproducible and restartable R analysis} \description{ -Provides intuitive functions for caching R objects, encouraging faster -reproducible and restartable R analysis +Provides intuitive functions for caching R objects, encouraging + reproducible, restartable, and distributed R analysis. The user selects a + location to store caches, and then provides nothing more than a cache name + and instructions (R code) for how to produce the R object. Also + provides some advanced options like environment assignments, recreating or + reloading caches, and cluster compute bindings (using the 'batchtools' + package) making it flexible enough for use in large-scale data analysis + projects. } \references{ \url{https://github.com/databio/simpleCache} diff --git a/man/simpleCache.Rd b/man/simpleCache.Rd index 9338206..f5c714e 100644 --- a/man/simpleCache.Rd +++ b/man/simpleCache.Rd @@ -6,11 +6,12 @@ \usage{ simpleCache(cacheName, instruction = NULL, buildEnvir = NULL, reload = FALSE, recreate = FALSE, noload = FALSE, - cacheDir = getOption("RCACHE.DIR"), cacheSubDir = NULL, timer = FALSE, - buildDir = getOption("RBUILD.DIR"), assignToVariable = NULL, - loadEnvir = parent.frame(), searchEnvir = getOption("SIMPLECACHE.ENV"), - nofail = FALSE, batchRegistry = NULL, batchResources = NULL, - pepSettings = NULL, ignoreLock = FALSE, lifespan = NULL) + cacheDir = getOption("RCACHE.DIR"), cacheSubDir = NULL, + timer = FALSE, buildDir = getOption("RBUILD.DIR"), + assignToVariable = NULL, loadEnvir = parent.frame(), + searchEnvir = getOption("SIMPLECACHE.ENV"), nofail = FALSE, + batchRegistry = NULL, batchResources = NULL, pepSettings = NULL, + ignoreLock = FALSE, lifespan = NULL) } \arguments{ \item{cacheName}{A character vector for a unique name for the cache. Be careful.} From fcd6fd81c410522aaa62a23663bf9f2dd5f21a82 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 24 Oct 2018 15:33:38 -0400 Subject: [PATCH 10/15] start with no cache dir set --- tests/testthat/test_all.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index 3ed304f..d219919 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -140,6 +140,7 @@ test_that("option setting works", { }) test_that("Cache dir fetch works", { + options(RCACHE.DIR = NULL) expect_true(is.null(getCacheDir())) setCacheDir(tempdir()) expect_false(is.null(getCacheDir())) From 8b78381e357d23e56b4ff2dfdcc8b6b255e7126a Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 24 Oct 2018 16:18:42 -0400 Subject: [PATCH 11/15] use cache dir option fetcher --- R/cacheDirectories.R | 2 +- R/deleteCache.R | 2 +- R/listCaches.R | 2 +- R/simpleCache.R | 2 +- R/storeCache.R | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/cacheDirectories.R b/R/cacheDirectories.R index cb21c3c..bb50e71 100644 --- a/R/cacheDirectories.R +++ b/R/cacheDirectories.R @@ -45,7 +45,7 @@ setCacheBuildDir = function(cacheBuildDir=NULL) { .setDir("RBUILD.DIR", cacheBui #' @export simpleCacheOptions = function() { message("RESOURCES.RCACHE:\t", getOption("RESOURCES.RCACHE")) - message("RCACHE.DIR:\t", getOption("RCACHE.DIR")) + message("RCACHE.DIR:\t", getCacheDir()) message("RBUILD.DIR:\t", getOption("RBUILD.DIR")) message("SIMPLECACHE.ENV:\t", getOption("SIMPLECACHE.ENV")) } diff --git a/R/deleteCache.R b/R/deleteCache.R index a6f6974..6327aa5 100644 --- a/R/deleteCache.R +++ b/R/deleteCache.R @@ -8,7 +8,7 @@ #' @export #' @example #' R/examples/example.R -deleteCaches = function(cacheNames, cacheDir=getOption("RCACHE.DIR"), +deleteCaches = function(cacheNames, cacheDir=getCacheDir(), force=FALSE) { if (force) { diff --git a/R/listCaches.R b/R/listCaches.R index 098b129..c04e17e 100644 --- a/R/listCaches.R +++ b/R/listCaches.R @@ -9,7 +9,7 @@ #' @example #' R/examples/example.R listCaches = function(cacheSubDir="") { - cacheDirFiles = list.files(paste0(getOption("RCACHE.DIR"), cacheSubDir)) + cacheDirFiles = list.files(paste0(getCacheDir(), cacheSubDir)) cacheDirFiles[which(sapply(cacheDirFiles, function(f) endsWith(f, ".RData")))] } diff --git a/R/simpleCache.R b/R/simpleCache.R index c95c2f4..3ed8155 100755 --- a/R/simpleCache.R +++ b/R/simpleCache.R @@ -88,7 +88,7 @@ #' R/examples/example.R simpleCache = function(cacheName, instruction=NULL, buildEnvir=NULL, reload=FALSE, recreate=FALSE, noload=FALSE, - cacheDir=getOption("RCACHE.DIR"), cacheSubDir=NULL, timer=FALSE, + cacheDir=getCacheDir(), cacheSubDir=NULL, timer=FALSE, buildDir=getOption("RBUILD.DIR"), assignToVariable=NULL, loadEnvir=parent.frame(), searchEnvir=getOption("SIMPLECACHE.ENV"), nofail=FALSE, batchRegistry=NULL, batchResources=NULL, pepSettings=NULL, diff --git a/R/storeCache.R b/R/storeCache.R index b684b51..73caae2 100644 --- a/R/storeCache.R +++ b/R/storeCache.R @@ -19,7 +19,7 @@ #' @export #' @example #' R/examples/example.R -storeCache = function(cacheName, cacheDir = getOption("RCACHE.DIR"), +storeCache = function(cacheName, cacheDir = getCacheDir(), cacheSubDir = NULL, recreate=FALSE) { if(!is.null(cacheSubDir)) { From edd1ef0df32db40f7e2cc0bce88d11d71a4861e6 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Wed, 24 Oct 2018 16:43:38 -0400 Subject: [PATCH 12/15] roxygenize --- man/deleteCaches.Rd | 3 +-- man/simpleCache.Rd | 6 +++--- man/storeCache.Rd | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/man/deleteCaches.Rd b/man/deleteCaches.Rd index 61f380f..ff70706 100644 --- a/man/deleteCaches.Rd +++ b/man/deleteCaches.Rd @@ -4,8 +4,7 @@ \alias{deleteCaches} \title{Deletes caches} \usage{ -deleteCaches(cacheNames, cacheDir = getOption("RCACHE.DIR"), - force = FALSE) +deleteCaches(cacheNames, cacheDir = getCacheDir(), force = FALSE) } \arguments{ \item{cacheNames}{Name(s) of the cache to delete} diff --git a/man/simpleCache.Rd b/man/simpleCache.Rd index f5c714e..b4d2ce9 100644 --- a/man/simpleCache.Rd +++ b/man/simpleCache.Rd @@ -6,9 +6,9 @@ \usage{ simpleCache(cacheName, instruction = NULL, buildEnvir = NULL, reload = FALSE, recreate = FALSE, noload = FALSE, - cacheDir = getOption("RCACHE.DIR"), cacheSubDir = NULL, - timer = FALSE, buildDir = getOption("RBUILD.DIR"), - assignToVariable = NULL, loadEnvir = parent.frame(), + cacheDir = getCacheDir(), cacheSubDir = NULL, timer = FALSE, + buildDir = getOption("RBUILD.DIR"), assignToVariable = NULL, + loadEnvir = parent.frame(), searchEnvir = getOption("SIMPLECACHE.ENV"), nofail = FALSE, batchRegistry = NULL, batchResources = NULL, pepSettings = NULL, ignoreLock = FALSE, lifespan = NULL) diff --git a/man/storeCache.Rd b/man/storeCache.Rd index 306b21d..3f5bfe3 100644 --- a/man/storeCache.Rd +++ b/man/storeCache.Rd @@ -4,8 +4,8 @@ \alias{storeCache} \title{Stores as a cache an already-produced R object} \usage{ -storeCache(cacheName, cacheDir = getOption("RCACHE.DIR"), - cacheSubDir = NULL, recreate = FALSE) +storeCache(cacheName, cacheDir = getCacheDir(), cacheSubDir = NULL, + recreate = FALSE) } \arguments{ \item{cacheName}{Unique name for the cache (and R object to be cached).} From 8446e4674110823e9feb62d1cd73029b11cf2f15 Mon Sep 17 00:00:00 2001 From: nsheff Date: Tue, 26 Feb 2019 11:35:49 -0500 Subject: [PATCH 13/15] Tests on windows. Fix #37 --- tests/testthat/test_all.R | 10 +++++++--- tests/testthat/test_cache_lifespan.R | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/testthat/test_all.R b/tests/testthat/test_all.R index d219919..2ac54f3 100644 --- a/tests/testthat/test_all.R +++ b/tests/testthat/test_all.R @@ -122,12 +122,16 @@ test_that("option setting works", { setCacheBuildDir(tempdir()) addCacheSearchEnvironment("cacheEnv") + # Windows uses double slashes, which get consumed weirdly by grep; + # This command will replace double slashes with quadruple slashes, + # which behave correctly in grep. + grep_tempdir = gsub("\\\\", "\\\\\\\\", tempdir()) # capture output and check options_out <- capture_messages(simpleCacheOptions()) - expect_true(grepl(tempdir(), options_out[1])) - expect_true(grepl(tempdir(), options_out[2])) - expect_true(grepl(tempdir(), options_out[3])) + expect_true(grepl(grep_tempdir, options_out[1])) + expect_true(grepl(grep_tempdir, options_out[2])) + expect_true(grepl(grep_tempdir, options_out[3])) expect_true(grepl("cacheEnv", options_out[4])) # reset the cache search option diff --git a/tests/testthat/test_cache_lifespan.R b/tests/testthat/test_cache_lifespan.R index 914122b..eb768fe 100644 --- a/tests/testthat/test_cache_lifespan.R +++ b/tests/testthat/test_cache_lifespan.R @@ -43,11 +43,11 @@ my_test_that("Cache file is replaced if no lifespan is specified and recreate=TR mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) expect_true(file_test("-f", fp)) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime Sys.sleep(1) # Delay so that our time comparison can work. mySimpleCache("testDF", recreate=TRUE, instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 > t0) }) @@ -59,10 +59,10 @@ my_test_that("Cache remains unchanged if younger than explicit lifespan", { mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) expect_true(file_test("-f", fp)) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime mySimpleCache("testDF", lifespan=0.5, instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 == t0) }) @@ -74,11 +74,11 @@ my_test_that("Cache is replaced if older than explicit lifespan", { mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) expect_true(file_test("-f", fp)) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime Sys.sleep(1) # Time difference comparison reliability. mySimpleCache("testDF", lifespan=0, instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 > t0) }) @@ -90,11 +90,11 @@ my_test_that("Cache is replaced if recreate=TRUE even if cache is fresh", { mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_true(file_test("-f", fp)) expect_equal(1, countCacheItems()) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime Sys.sleep(1) # Time difference comparison reliability. mySimpleCache("testDF", recreate=TRUE, lifespan=0, instruction={ buildTestFrame() }) expect_equal(1, countCacheItems()) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 > t0) }) @@ -104,10 +104,10 @@ my_test_that("simpleCache can pick up option specifying max cache age.", { expect_false(file_test("-f", fp)) mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_true(file_test("-f", fp)) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime Sys.sleep(1) # Time difference comparison reliability. mySimpleCache("testDF", instruction={ buildTestFrame() }) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 > t0) }) @@ -117,12 +117,12 @@ my_test_that("Direct lifespan specification is preferred to background option", expect_false(file_test("-f", fp)) mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_true(file_test("-f", fp)) - t0 = file.info(fp)$ctime + t0 = file.info(fp)$mtime Sys.sleep(1) mySimpleCache("testDF", instruction={ buildTestFrame() }) expect_equal(t0, file.info(fp)$ctime) # Cache is fresh via MAX.CACHE.AGE. Sys.sleep(1) # Time difference comparison reliability. mySimpleCache("testDF", lifespan=0, instruction={ buildTestFrame() }) - t1 = file.info(fp)$ctime + t1 = file.info(fp)$mtime expect_true(t1 > t0) # Cache is stale via lifespan. }) From 7a55c17a4a9a81488b2b595bf7e37afb190a830b Mon Sep 17 00:00:00 2001 From: nsheff Date: Tue, 26 Feb 2019 11:42:05 -0500 Subject: [PATCH 14/15] change ctime to mtime --- R/utility.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utility.R b/R/utility.R index 68f9d58..e3b1992 100644 --- a/R/utility.R +++ b/R/utility.R @@ -29,7 +29,7 @@ if (!utils::file_test("-f", pathCacheFile)) { return(FALSE) } if (is.null(lifespan)) { lifespan = getOption("MAX.CACHE.AGE") } if (is.null(lifespan)) { return(FALSE) } - cacheTime = file.info(pathCacheFile)$ctime + cacheTime = file.info(pathCacheFile)$mtime cacheAge = difftime(Sys.time(), cacheTime, units="days") as.numeric(cacheAge) > as.numeric(lifespan) } From a4b93e0aa741bfa5152931de4582453a17ecf1ff Mon Sep 17 00:00:00 2001 From: nsheff Date: Tue, 26 Feb 2019 11:48:28 -0500 Subject: [PATCH 15/15] update changelog --- DESCRIPTION | 2 +- NEWS => NEWS.md | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) rename NEWS => NEWS.md (67%) diff --git a/DESCRIPTION b/DESCRIPTION index 0a0a5c4..a0bdf62 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: simpleCache Version: 0.4.1 -Date: 2018-06-08 +Date: 2019-02-26 Title: Simply Caching R Objects Description: Provides intuitive functions for caching R objects, encouraging reproducible, restartable, and distributed R analysis. The user selects a diff --git a/NEWS b/NEWS.md similarity index 67% rename from NEWS rename to NEWS.md index 247dc39..6fd7f24 100644 --- a/NEWS +++ b/NEWS.md @@ -1,13 +1,19 @@ # Change log All notable changes to this project will be documented in this file. -## [0.4.0] -- 2017-12-20 +## simpleCache [0.4.1] -- 2019-02-26 + + - fixes unit tests on windows + - fixes lifespan bug that used creation time instead of modification time + - allow arg-less directory setting to default to current working dir + +## simpleCache [0.4.0] -- 2017-12-20 - adds a lifespan arg to simpleCache() to create auto-expiring caches - remove unnecessary parse argument to simpleCache() - viewCacheDirs() renamed to simpleCacheOptions() -## [0.3.1] -- 2017-08-21 +## simpleCache [0.3.1] -- 2017-08-21 - fixed a bug in unit tests that left behind a test cache in user home dir. - changes cache building to happen in parent.frame() @@ -15,7 +21,7 @@ All notable changes to this project will be documented in this file. - added deleteCaches() function and docs - reduced size of unit test cache for speed increase -## [0.3.0] -- 2017-08-21 +## simpleCache [0.3.0] -- 2017-08-21 - switched default cache dir to tempdir() - changed availCaches() to listCaches() @@ -23,15 +29,15 @@ All notable changes to this project will be documented in this file. packages are available for cache building -## [0.2.1] -- 2017-07-30 +## simpleCache [0.2.1] -- 2017-07-30 - added examples -## [0.2.0] -- 2017-07-30 +## simpleCache [0.2.0] -- 2017-07-30 - support for batchjobs parallel processing - docs, prep for submission to CRAN -## [0.0.1] +## simpleCache [0.0.1] - long-term stable version