File: future_cache_path.R

package info (click to toggle)
r-cran-future.batchtools 0.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 436 kB
  • sloc: sh: 54; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#' @importFrom utils file_test sessionInfo
future_cache_path <- local({
  ## The subfolder used for this session
  dir <- NULL

  function(root_path = getOption("future.cache.path", Sys.getenv("R_FUTURE_CACHE_PATH", ".future")), absolute = TRUE, create = TRUE) {
    if (is.null(dir)) {
      id <- basename(tempdir())
      id <- gsub("Rtmp", "", id, fixed = TRUE)
      timestamp <- format(Sys.time(), format = "%Y%m%d_%H%M%S")
      dir <<- sprintf("%s-%s", timestamp, id)
    }
    
    path <- file.path(root_path, dir)
    if (create && !file_test("-d", path)) {
      dir.create(path, recursive = TRUE)
      pathname <- file.path(path, "sessioninfo.txt")
      writeLines(capture_output(print(sessionInfo())), con = pathname)
    }

    if (absolute) path <- normalizePath(path, mustWork = FALSE)

    path
  }
})