Skip to content

Commit a38d71b

Browse files
authored
Merge pull request #43 from databio/dev
Release 0.4.1
2 parents e4f3aa7 + a4b93e0 commit a38d71b

20 files changed

+152
-51
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: simpleCache
22
Version: 0.4.1
3-
Date: 2018-03-01
3+
Date: 2019-02-26
44
Title: Simply Caching R Objects
55
Description: Provides intuitive functions for caching R objects, encouraging
66
reproducible, restartable, and distributed R analysis. The user selects a
@@ -22,4 +22,4 @@ License: BSD_2_clause + file LICENSE
2222
Encoding: UTF-8
2323
URL: https://www.github.com/databio/simpleCache
2424
BugReports: https://www.github.com/databio/simpleCache
25-
RoxygenNote: 6.0.1.9000
25+
RoxygenNote: 6.1.0

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export(addCacheSearchEnvironment)
44
export(deleteCaches)
5+
export(getCacheDir)
56
export(listCaches)
67
export(loadCaches)
78
export(resetCacheSearchEnvironment)

NEWS renamed to NEWS.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
# Change log
22
All notable changes to this project will be documented in this file.
33

4-
## [0.4.0] -- 2017-12-20
4+
## simpleCache [0.4.1] -- 2019-02-26
5+
6+
- fixes unit tests on windows
7+
- fixes lifespan bug that used creation time instead of modification time
8+
- allow arg-less directory setting to default to current working dir
9+
10+
## simpleCache [0.4.0] -- 2017-12-20
511

612
- adds a lifespan arg to simpleCache() to create auto-expiring caches
713
- remove unnecessary parse argument to simpleCache()
814
- viewCacheDirs() renamed to simpleCacheOptions()
915

10-
## [0.3.1] -- 2017-08-21
16+
## simpleCache [0.3.1] -- 2017-08-21
1117

1218
- fixed a bug in unit tests that left behind a test cache in user home dir.
1319
- changes cache building to happen in parent.frame()
1420
- repaired vignette so R code is displayed properly
1521
- added deleteCaches() function and docs
1622
- reduced size of unit test cache for speed increase
1723

18-
## [0.3.0] -- 2017-08-21
24+
## simpleCache [0.3.0] -- 2017-08-21
1925

2026
- switched default cache dir to tempdir()
2127
- changed availCaches() to listCaches()
2228
- changes cache building to happen in globalenv(), so that any loaded
2329
packages are available for cache building
2430

2531

26-
## [0.2.1] -- 2017-07-30
32+
## simpleCache [0.2.1] -- 2017-07-30
2733

2834
- added examples
2935

30-
## [0.2.0] -- 2017-07-30
36+
## simpleCache [0.2.0] -- 2017-07-30
3137

3238
- support for batchjobs parallel processing
3339
- docs, prep for submission to CRAN
3440

35-
## [0.0.1]
41+
## simpleCache [0.0.1]
3642

3743
- long-term stable version

R/cacheDirectories.R

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
#' @export
1313
#' @example
1414
#' R/examples/example.R
15-
setCacheDir = function(cacheDir) {
16-
options(RCACHE.DIR=cacheDir)
17-
}
15+
setCacheDir = function(cacheDir=NULL) { .setDir("RCACHE.DIR", cacheDir) }
16+
17+
#' Fetcher of the currently set cache directory.
18+
#'
19+
#' \code{getCacheDir} retrieves the value of the option that stores the currently
20+
#' set cache directory path.
21+
#'
22+
#' @return If the option is set, the path to the currently set cache directory; otherwise, \code{NULL}.
23+
#' @export
24+
getCacheDir = function() { getOption("RCACHE.DIR") }
1825

1926
#' Set shared cache directory
2027
#'
@@ -24,25 +31,21 @@ setCacheDir = function(cacheDir) {
2431
#'
2532
#' @param sharedCacheDir Directory where shared caches should be stored
2633
#' @export
27-
setSharedCacheDir = function(sharedCacheDir) {
28-
options(RESOURCES.RCACHE=sharedCacheDir)
29-
}
34+
setSharedCacheDir = function(sharedCacheDir=NULL) { .setDir("RESOURCES.RCACHE", sharedCacheDir) }
3035

3136
#' Sets local cache build directory with scripts for building files.
3237
#'
3338
#' @param cacheBuildDir Directory where build scripts are stored.
3439
#' @export
35-
setCacheBuildDir = function(cacheBuildDir) {
36-
options(RBUILD.DIR=cacheBuildDir)
37-
}
40+
setCacheBuildDir = function(cacheBuildDir=NULL) { .setDir("RBUILD.DIR", cacheBuildDir) }
3841

3942
#' View simpleCache options
4043
#'
4144
#' Views simpleCache global variables
4245
#' @export
4346
simpleCacheOptions = function() {
4447
message("RESOURCES.RCACHE:\t", getOption("RESOURCES.RCACHE"))
45-
message("RCACHE.DIR:\t", getOption("RCACHE.DIR"))
48+
message("RCACHE.DIR:\t", getCacheDir())
4649
message("RBUILD.DIR:\t", getOption("RBUILD.DIR"))
4750
message("SIMPLECACHE.ENV:\t", getOption("SIMPLECACHE.ENV"))
4851
}
@@ -66,3 +69,9 @@ resetCacheSearchEnvironment = function() {
6669
options(SIMPLECACHE.ENV=NULL)
6770
}
6871

72+
73+
.setDir = function(optname, dirpath=NULL) {
74+
diropts = list(ifelse(is.null(dirpath), getwd(), dirpath))
75+
names(diropts) = optname
76+
do.call(options, diropts)
77+
}

R/deleteCache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @export
99
#' @example
1010
#' R/examples/example.R
11-
deleteCaches = function(cacheNames, cacheDir=getOption("RCACHE.DIR"),
11+
deleteCaches = function(cacheNames, cacheDir=getCacheDir(),
1212
force=FALSE) {
1313

1414
if (force) {

R/listCaches.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' @example
1010
#' R/examples/example.R
1111
listCaches = function(cacheSubDir="") {
12-
list.files(paste0(getOption("RCACHE.DIR"), cacheSubDir))
12+
cacheDirFiles = list.files(paste0(getCacheDir(), cacheSubDir))
13+
cacheDirFiles[which(sapply(cacheDirFiles, function(f) endsWith(f, ".RData")))]
1314
}
1415

R/simpleCache.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
#' R/examples/example.R
8989
simpleCache = function(cacheName, instruction=NULL, buildEnvir=NULL,
9090
reload=FALSE, recreate=FALSE, noload=FALSE,
91-
cacheDir=getOption("RCACHE.DIR"), cacheSubDir=NULL, timer=FALSE,
91+
cacheDir=getCacheDir(), cacheSubDir=NULL, timer=FALSE,
9292
buildDir=getOption("RBUILD.DIR"), assignToVariable=NULL,
9393
loadEnvir=parent.frame(), searchEnvir=getOption("SIMPLECACHE.ENV"),
9494
nofail=FALSE, batchRegistry=NULL, batchResources=NULL, pepSettings=NULL,
@@ -134,7 +134,9 @@ simpleCache = function(cacheName, instruction=NULL, buildEnvir=NULL,
134134
cacheWhere = NULL
135135

136136
for ( curEnv in searchEnvir ) {
137-
if(exists(cacheName, where=get(curEnv))) {
137+
if(! ( exists(curEnv) && is.environment(get(curEnv))) ) {
138+
warning(curEnv, " is not an environment.")
139+
} else if( exists(cacheName, where=get(curEnv))) {
138140
cacheExists = TRUE
139141
cacheWhere = curEnv
140142
break

R/storeCache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' @export
2020
#' @example
2121
#' R/examples/example.R
22-
storeCache = function(cacheName, cacheDir = getOption("RCACHE.DIR"),
22+
storeCache = function(cacheName, cacheDir = getCacheDir(),
2323
cacheSubDir = NULL, recreate=FALSE) {
2424

2525
if(!is.null(cacheSubDir)) {

R/utility.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
if (!utils::file_test("-f", pathCacheFile)) { return(FALSE) }
3030
if (is.null(lifespan)) { lifespan = getOption("MAX.CACHE.AGE") }
3131
if (is.null(lifespan)) { return(FALSE) }
32-
cacheTime = file.info(pathCacheFile)$ctime
32+
cacheTime = file.info(pathCacheFile)$mtime
3333
cacheAge = difftime(Sys.time(), cacheTime, units="days")
3434
as.numeric(cacheAge) > as.numeric(lifespan)
3535
}

man/deleteCaches.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)