tests/testthat/test_cacheLocation.R

context("cacheLocation")

test_that("Monte-Carlo simulations are only cached inside the temporary directory", {
  skip_if_not_installed("R.cache")
  
  # normalizePath() resolves symbolic links and repeated separators only for paths that
  # exist, but the root path is not created before the first simulation is saved,
  # e.g. on macOS tempdir() is /var/folders/.../T//Rtmp... and /var links to /private/var,
  # hence canonicalise the longest existing part of a path and append the remainder
  canonicalPath <- function(path) {
    rest <- character(0)
    while (!file.exists(path) && dirname(path) != path) {
      rest <- c(basename(path), rest)
      path <- dirname(path)
    }
    paste(c(normalizePath(path, winslash = "/", mustWork = FALSE), rest), collapse = "/")
  }

  # tests/testthat.R redirects the R.cache root path into tempdir(), without it
  # simulations are saved in the cache directory of the user, which is not allowed on CRAN
  root <- canonicalPath(R.cache::getCacheRootPath())
  temp <- canonicalPath(tempdir())
  expect_true(startsWith(root, paste0(temp, "/")))
  
  # a call with the default options saves on the file system,
  # the simulation has to be saved below the redirected root
  testfilter <- lowpassFilter::lowpassFilter(type = "bessel", param = list(pole = 4, cutoff = 0.1),
                                             sr = 1e4)
  before <- list.files(file.path(root, "stepR"))
  getCritVal(n = 137L, filter = testfilter, r = 1e3L)
  after <- list.files(file.path(root, "stepR"))
  expect_true(length(setdiff(after, before)) > 0L)
})

Try the clampSeg package in your browser

Any scripts or data that you put into this service are public.

clampSeg documentation built on Oct. 11, 2026, 5:09 p.m.