Running 'DEPRECATED.R' [172s]
  Running 'Object.getChecksum.R' [0s]
  Running 'StaticMethodsAndNamespaces.R' [1s]
  Running 'addMemoization.R' [194s]
  Running 'assertDigest.R' [160s]
  Running 'clearCache.R' [247s]
  Running 'evalWithMemoization.R' [1s]
  Running 'findOSCachePath.R' [0s]
  Running 'getCachePath.R' [164s]
  Running 'getCacheRootPath.R' [160s]
  Running 'loadCache.R' [179s]
  Running 'memoizedCall.R' [203s]
  Running 'readCacheHeader.R' [189s]
  Running 'setCachePath.R' [191s]
  Running 'setCacheRootPath.R' [25s]
  Running 'textPrompt.R' [163s]
Running the tests in 'tests/DEPRECATED.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > options(R.cache.rootPath = NULL)
  > 
  > ## -----------------------------------------------
  > ## DEPRECATED & DEFUNCT
  > ## -----------------------------------------------
  > options("R.cache.path"="foo")
  > res <- tryCatch(getCacheRootPath(), error = identity)
  > print(res)
  <defunctError in getCacheRootPath.default(): R.cache option 'R.cache::path' has been renamed to 'R.cache.rootPath'>
  > stopifnot(inherits(res, "error"))
  > options("R.cache.path"=NULL)
  > 
  > Sys.setenv("R_CACHE_PATH"="foo")
  > res <- tryCatch(getCacheRootPath(), error = identity)
  > print(res)
  <defunctError in getCacheRootPath.default(): R.cache environment variable 'R_CACHE_PATH' is deprecated. Use option 'R.cache.rootPath' instead>
  > stopifnot(inherits(res, "error"))
  > Sys.setenv("R_CACHE_PATH"="")
  > 
  > proc.time()
     user  system elapsed 
     0.14    0.15    0.28 
Running the tests in 'tests/addMemoization.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > # Use an empty temporary file cache
  > setCacheRootPath(path=file.path(tempdir()))
  > clearCache(recursive=TRUE, prompt=FALSE)
  > dirs <- c("tests", "addMemoization")
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Define function to be memoized
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > sleep <- function(time) {
  +   cat(sprintf("Sleeping for %g seconds...\n", time))
  +   Sys.sleep(time)
  +   cat(sprintf("Sleeping for %g seconds...done\n", time))
  +   time
  + }
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Test memoization
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > sleep <- addMemoization(sleep)
  > 
  > # There will be no cache hit for the first call
  > t0 <- system.time({
  +   res0 <- sleep(1.5)
  + })[3]
  Sleeping for 1.5 seconds...
  Sleeping for 1.5 seconds...done
  > print(t0)
  elapsed 
     1.54 
  > 
  > # The second will have a cache hit and therefore
  > # return the memoized results momentarily.
  > t1 <- system.time({
  +   res1 <- sleep(1.5)
  + })[3]
  > print(t1)
  elapsed 
        0 
  > print(t1/t0)
  elapsed 
        0 
  > 
  > # Sanity check
  > stopifnot(identical(res1, res0))
  > 
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Don't memoize already memoized functions
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > sleep2 <- addMemoization(sleep)
  > stopifnot(identical(sleep2, sleep))
  > 
  > sleep3 <- addMemoization("sleep")
  > stopifnot(identical(sleep3, sleep))
  > 
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Exception handling
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > res <- try(addMemoization("non-existing-function"), silent=TRUE)
  > stopifnot(inherits(res, "try-error"))
  > 
  > res <- try(addMemoization(NULL), silent=TRUE)
  > stopifnot(inherits(res, "try-error"))
  > 
  > proc.time()
     user  system elapsed 
     2.73   24.39   29.15 
Running the tests in 'tests/assertDigest.R' failed.
Complete output:
  > R.cache:::.assertDigest()
  > 
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > R.cache:::.assertDigest()
  > 
  > proc.time()
     user  system elapsed 
     0.28    0.15    0.37 
Running the tests in 'tests/clearCache.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > ## Use an empty temporary file cache
  > setCacheRootPath(path=file.path(tempdir()))
  > 
  > ## Try to clear it
  > clearCache(recursive=TRUE, prompt=FALSE)
  > clearCache(recursive=TRUE, prompt=TRUE)
  Nothing to clear. Cache directory is empty: D:/temp/RtmpuykuSY
  
  > 
  > dirs <- c("tests", "clearCache")
  > saveCache(1, key=list("clearCache"), dirs=dirs)
  > 
  > clearCache(recursive=FALSE, prompt=TRUE)
  Are you sure you want to delete the 0 files and 1 directories in 'D:/temp/RtmpuykuSY'? [y/N]: 
  > clearCache(recursive=TRUE, prompt=TRUE)
  Are you sure you want to delete the 1 files and 2 directories in 'D:/temp/RtmpuykuSY'? [y/N]: 
  > clearCache(recursive=FALSE, prompt=FALSE)
  > clearCache(recursive=TRUE, prompt=FALSE)
  > 
  > proc.time()
     user  system elapsed 
     8.07   74.68   85.87 
Running the tests in 'tests/getCachePath.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > root <- getCacheRootPath()
  > print(root)
  [1] "D:\\temp\\RtmpwFMJZQ/.cache/R/R.cache"
  > 
  > path <- getCachePath(dirs=c("abc", "def"))
  > print(path)
  [1] "D:\\temp\\RtmpwFMJZQ/.cache/R/R.cache/abc/def"
  > 
  > path <- getCachePath(dirs=c("abc", "def"), path="subdir")
  > print(path)
  [1] "D:\\temp\\RtmpwFMJZQ/.cache/R/R.cache/subdir"
  > 
  > proc.time()
     user  system elapsed 
     0.32    0.04    0.36 
Running the tests in 'tests/getCacheRootPath.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > setupCacheRootPath <- R.cache:::setupCacheRootPath
  > 
  > oopts <- options()
  > 
  > tmpdir <- tempdir()
  > setCacheRootPath(path=tmpdir)
  > 
  > print(getCacheRootPath())
  [1] "D:\\temp\\RtmpQx2tzj"
  > 
  > setupCacheRootPath(defaultPath=tmpdir)
  > path <- getCacheRootPath(NULL)
  > print(path)
  [1] "D:\\temp\\RtmpQx2tzj"
  > stopifnot(identical(path, tmpdir))
  > 
  > options("R.cache.rootPath"=NULL)
  > print(getCacheRootPath())
  NULL
  > 
  > path <- getCacheRootPath(NULL)
  > print(path)
  NULL
  > stopifnot(is.null(path))
  > setupCacheRootPath(defaultPath=tmpdir)
  > 
  > path <- getCacheRootPath(NULL)
  > print(path)
  [1] "D:\\temp\\RtmpQx2tzj"
  > stopifnot(identical(path, tmpdir))
  > 
  > ## Reset
  > options(oopts)
  > 
  > proc.time()
     user  system elapsed 
     0.26    0.09    0.34 
Running the tests in 'tests/loadCache.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > oopts <- options("R.cache.compress")
  > 
  > simulate <- function(mean, sd) {
  +   # 1. Try to load cached data, if already generated
  +   key <- list(mean, sd)
  +   data <- loadCache(key)
  +   if (!is.null(data)) {
  +     cat("Loaded cached data\n")
  +     return(data)
  +   }
  + 
  +   # 2. If not available, generate it.
  +   cat("Generating data from scratch...")
  +   data <- rnorm(1000, mean=mean, sd=sd)
  +   Sys.sleep(1)             # Emulate slow algorithm
  +   cat("ok\n")
  +   saveCache(data, key=key, comment="simulate()")
  + 
  +   data
  + }
  > 
  > 
  > for (compress in c(FALSE, TRUE)) {
  +   options("R.cache.compress"=compress)
  + 
  +   data <- simulate(2.3, 3.0)
  +   data <- simulate(2.3, 3.5)
  +   data <- simulate(2.3, 3.0) # Will load cached data
  + 
  +   # Clean up
  +   file.remove(findCache(key=list(2.3,3.0)))
  +   file.remove(findCache(key=list(2.3,3.5)))
  + }
  Generating data from scratch...ok
  Generating data from scratch...ok
  Loaded cached data
  Generating data from scratch...ok
  Generating data from scratch...ok
  Loaded cached data
  > 
  > 
  > ## Exceptions
  > res <- try(findCache(key = NULL))
  Error in generateCache.default(key = key, ...) : 
    Argument 'key' must be a list, an environment: NULL
  > stopifnot(inherits(res, "try-error"))
  > 
  > ## Cleanup
  > options(oopts)
  > 
  > proc.time()
     user  system elapsed 
     0.32    0.14    4.81 
Running the tests in 'tests/memoizedCall.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > # Use an empty temporary file cache
  > setCacheRootPath(path=file.path(tempdir()))
  > clearCache(recursive=TRUE, prompt=FALSE)
  > dirs <- c("tests", "memoizedCall")
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Define function to be memoized
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > sleep <- function(time) {
  +   cat(sprintf("Sleeping for %g seconds...\n", time))
  +   Sys.sleep(time)
  +   cat(sprintf("Sleeping for %g seconds...done\n", time))
  +   time
  + }
  > 
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # Test memoization
  > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  > # There will be no cache hit for the first call
  > t0 <- system.time({
  +   res0 <- memoizedCall(sleep, time=1.5, dirs=dirs)
  + })[3]
  Sleeping for 1.5 seconds...
  Sleeping for 1.5 seconds...done
  > print(t0)
  elapsed 
     1.58 
  > 
  > # The second will have a cache hit and therefore
  > # return the memoized results momentarily.
  > t1 <- system.time({
  +   res1 <- memoizedCall(sleep, time=1.5, dirs=dirs)
  + })[3]
  > print(t1)
  elapsed 
     0.23 
  > if (t1 >= t0) {
  +   warning("Second call to memoizedCall() took longer than the first: ",
  +           t1, " >= ", t0)
  + }
  > 
  > # Sanity check
  > stopifnot(identical(res1, res0))
  > clearCache(recursive=TRUE)
  > 
  > proc.time()
     user  system elapsed 
     3.79   36.48   44.06 
Running the tests in 'tests/readCacheHeader.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > 
  > ## Use an empty temporary file cache
  > setCacheRootPath(path=file.path(tempdir()))
  > 
  > dirs <- c("tests", "readCacheHeader")
  > 
  > for (compress in c(FALSE, TRUE)) {
  +   pathname <- saveCache(1, key=list("readCacheHeader"), dirs=dirs, compress=compress)
  + 
  +   for (byName in c(FALSE, TRUE)) {
  +     if (byName) {
  +       hdr <- readCacheHeader(pathname)
  +     } else {
  +       con <- gzfile(pathname, open="rb")
  +       hdr <- readCacheHeader(con)
  +       close(con)
  +     }
  +     str(list(pathname=pathname, hdr=hdr))
  +   }
  + }
  List of 2
   $ pathname: chr "D:\\temp\\RtmpQnq9KQ/tests/readCacheHeader/351327a91bf868eddc966826e7b8de3e.Rcache"
   $ hdr     :List of 4
    ..$ identifier: chr "Rcache v0.1.7 (R package R.cache by Henrik Bengtsson)           "
    ..$ version   : chr "0.1.7"
    ..$ comment   : chr ""
    ..$ timestamp : POSIXct[1:1], format: "2024-03-23 09:27:02"
  List of 2
   $ pathname: chr "D:\\temp\\RtmpQnq9KQ/tests/readCacheHeader/351327a91bf868eddc966826e7b8de3e.Rcache"
   $ hdr     :List of 4
    ..$ identifier: chr "Rcache v0.1.7 (R package R.cache by Henrik Bengtsson)           "
    ..$ version   : chr "0.1.7"
    ..$ comment   : chr ""
    ..$ timestamp : POSIXct[1:1], format: "2024-03-23 09:27:02"
  List of 2
   $ pathname: chr "D:\\temp\\RtmpQnq9KQ/tests/readCacheHeader/351327a91bf868eddc966826e7b8de3e.Rcache.gz"
   $ hdr     :List of 4
    ..$ identifier: chr "Rcache v0.1.7 (R package R.cache by Henrik Bengtsson)           "
    ..$ version   : chr "0.1.7"
    ..$ comment   : chr ""
    ..$ timestamp : POSIXct[1:1], format: "2024-03-23 09:27:02"
  List of 2
   $ pathname: chr "D:\\temp\\RtmpQnq9KQ/tests/readCacheHeader/351327a91bf868eddc966826e7b8de3e.Rcache.gz"
   $ hdr     :List of 4
    ..$ identifier: chr "Rcache v0.1.7 (R package R.cache by Henrik Bengtsson)           "
    ..$ version   : chr "0.1.7"
    ..$ comment   : chr ""
    ..$ timestamp : POSIXct[1:1], format: "2024-03-23 09:27:02"
  > 
  > ## Cleanup
  > clearCache(recursive=TRUE)
  > 
  > proc.time()
     user  system elapsed 
     2.39   24.79   29.28 
Running the tests in 'tests/setCachePath.R' failed.
Complete output:
  > library("R.cache")
  R.cache v0.16.0 (2022-07-21 16:20:02 UTC) successfully loaded. See ?R.cache for help.
  > setCachePath <- R.cache:::setCachePath
  > 
  > ## Use an empty temporary file cache
  > tmpdir <- tempdir()
  > setCacheRootPath(path=tmpdir)
  > 
  > dirs <- c("tests", "readCacheHeader")
  > setCachePath(dirs=dirs, path=tmpdir)
  > 
  > ## Cleanup
  > clearCache(recursive=TRUE)
  > 
  > proc.time()
     user  system elapsed 
     2.90   21.65   25.70 
Running the tests in 'tests/textPrompt.R' failed.
Complete output:
  > textPrompt <- R.cache:::.textPrompt
  > 
  > ans <- textPrompt("Do you have a minute?")
  Do you have a minute? [Y/n]: 
  > print(ans)
  [1] "yes"
  > 
  > ans <- textPrompt("Do you have a minute?", options=c("yes", "no"))
  Do you have a minute? [yes/no]: 
  > print(ans)
  [1] "yes"
  > 
  > ## Output to standard error
  > ans <- textPrompt("Do you have a minute?", type="message")
  Do you have a minute? [Y/n]: 
  > print(ans)
  [1] "yes"
  > 
  > ## Output to standard output
  > ans <- textPrompt("Do you have a minute?", type="output")
  Do you have a minute? [Y/n]: 
  > print(ans)
  [1] "yes"
  > 
  > proc.time()
     user  system elapsed 
     0.29    0.07    0.31