Skip to content

Commit

Permalink
Merge pull request #402 from PredictiveEcology/cacheIdForced
Browse files Browse the repository at this point in the history
cacheId bugfix
  • Loading branch information
eliotmcintire authored Sep 19, 2024
2 parents 6f6cef4 + 82a3617 commit 631cc06
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ SystemRequirements: 'unrar' (Linux/macOS) or '7-Zip' (Windows) to work with '.ra
URL:
https://reproducible.predictiveecology.org,
https://github.com/PredictiveEcology/reproducible
Date: 2024-07-19
Version: 2.1.1.9005
Date: 2024-09-17
Version: 2.1.1.9006
Authors@R:
c(person(given = "Eliot J B",
family = "McIntire",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* improved handling of symlinks in `remapFileNames()`;
* pass `terra::project()` arguments `use_gdal` and `by_util` through `projectTo()` to `terra::project()`;

## Bugfix
* When forcing `cacheId`, e.g., in `Cache(..., cacheId = "myCacheItem")`, `myCacheItem` was not used. Fixed.

# reproducible 2.1.0

## New
Expand Down
1 change: 0 additions & 1 deletion R/DBI.R
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ loadFromCache <- function(cachePath = getOption("reproducible.cachePath"),

if (length(sameCacheID)) {
# if (!identical(whereInStack("sim"), .GlobalEnv)) {
# browser()
# format <- setdiff(c("rds", "qs"), format)
# message("User tried to change options('reproducible.cacheSaveFormat') for an ",
# "existing cache, while using a simList. ",
Expand Down
4 changes: 3 additions & 1 deletion R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ Cache <-
messageCache("cacheId is not same as calculated hash. Manually searching for cacheId:", cacheId,
verbose = verbose
)
sc <- showCacheFast(cacheId = outputHashManual)
if (NROW(sc))
inRepos$isInRepo <- sc[1,]
}
outputHash <- outputHashManual
}
Expand Down Expand Up @@ -1545,7 +1548,6 @@ getFunctionName2 <- function(mc) {
# The next line works for any object that is NOT in a ..., because the
# object never shows up in the environment; it is passed through
# mced <- names(CacheMatchedCall)
# if (exists("aaaa")) browser()

# if (!is.null(unlist(argsToKeep))) {
FUNcapturedList <- as.list(FUNcaptured[-1])
Expand Down
9 changes: 6 additions & 3 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ reproducibleOptions <- function() {
reproducible.timeout = 1200,
reproducible.useCache = TRUE, # override Cache function
reproducible.useCloud = FALSE, #
reproducible.useDBI = {getEnv("R_REPRODUCIBLE_USE_DBI",
default = useDBI(getOption("reproducible.useDBI", NULL), # a user may have set it before this runs; keep setting
verbose = interactive() - (useDBI() + 1)), # `FALSE` is useMultipleDBFiles now
reproducible.useDBI = {
getEnv("R_REPRODUCIBLE_USE_DBI",
default = {
useDBI(getOption("reproducible.useDBI", NULL), # a user may have set it before this runs; keep setting
verbose = interactive() - (useDBI() + 1), default = TRUE)
}, # `FALSE` is useMultipleDBFiles now
allowed = c("true", "false")
) |> as.logical()},
reproducible.useGdown = FALSE,
Expand Down
1 change: 0 additions & 1 deletion R/postProcessTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,6 @@ gdalTransform <- function(from, cropTo, projectTo, maskTo, writeTo, verbose) {
# "-overwrite"
# )))
#
# browser()
terra::writeVector(maskTo, filename = tf2)
system.time(sf::gdal_utils(util = "vectortranslate", source = "C:/Eliot/GitHub/Edehzhie/modules/fireSense_dataPrepFit/data/NFDB_poly_20210707.shp",
destination = tf, options =
Expand Down
4 changes: 2 additions & 2 deletions R/showCacheEtc.R
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ checkFutures <- function(verbose = getOption("reproducible.verbose")) {
}
}

useDBI <- function(set = NULL, verbose = getOption("reproducible.verbose")) {
useDBI <- function(set = NULL, verbose = getOption("reproducible.verbose"), default = TRUE) {
canSwitch <- TRUE
if (!is.null(set)) {
if (isTRUE(set)) {
Expand All @@ -717,7 +717,7 @@ useDBI <- function(set = NULL, verbose = getOption("reproducible.verbose")) {
options("reproducible.useDBI" = set)
}
}
ud <- getOption("reproducible.useDBI", TRUE)
ud <- getOption("reproducible.useDBI", default)
if (isTRUE(ud)) {
drv <- getOption("reproducible.drv")
if (is.null(drv)) {
Expand Down
26 changes: 26 additions & 0 deletions tests/testthat/test-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -1872,3 +1872,29 @@ test_that("test omitArgs = 'x', #400", {
omitArgs = c("x")))

})


test_that("cacheId = 'customName'", {
testInit()
opts <- options(reproducible.cachePath = tmpdir)
on.exit(options(opts), add = TRUE)

fnName <- "rnorm_this_one"
d <- rnorm(2) |> Cache(.functionName = fnName, cacheId = "myCacheObj")
e <- rnorm(3) |> Cache(.functionName = fnName, cacheId = "myCacheObj")
expect_true(all.equalWONewCache(e, d))

rudbi <- getOption("reproducible.useDBI")


newDBI <- setdiff(c(TRUE, FALSE), rudbi)
opts <- options(reproducible.useDBI = newDBI)
on.exit(options(opts))

f <- rnorm(4) |> Cache(.functionName = fnName, cacheId = "myCacheObj")
g <- rnorm(5) |> Cache(.functionName = fnName, cacheId = "myCacheObj")
expect_true(all.equalWONewCache(e, d))
expect_true(all.equalWONewCache(e, f))
expect_true(all.equalWONewCache(e, g))
})

0 comments on commit 631cc06

Please sign in to comment.