File: findOSCachePath.R

package info (click to toggle)
r-cran-r.cache 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 392 kB
  • sloc: sh: 14; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (2)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(R.cache)

findOSCachePath <- R.cache:::findOSCachePath
getOS <- R.cache:::getOS
message("findOSCachePath() ...")

oses <- getOS()
if (isTRUE(as.logical(Sys.getenv("R_CHECK_FULL", "FALSE")))) {
  oses <- c("unix", "windows", "macos")
}

for (os in oses) {
  message("Operating system: ", sQuote(os))
  message("- getOS(): ", sQuote(getOS()))

  ## Fake the OS?
  fake_os <- (os != getOS())
  if (fake_os) {
    if (os == "windows") {
      Sys.setenv(LOCALAPPDATA = normalizePath("~/AppData/Local", mustWork = FALSE))
    }
  }

  path <- findOSCachePath(os)
  message("- findOSCachePath(): ", sQuote(path))
  
  if (getRversion() >= "4.0.0") {
    R_user_dir <- tools::R_user_dir
    path_R <- local({
      if (fake_os) {
        if (os == "macos") {
          tracer <- quote(Sys.info <- function() c(sysname = "Darwin"))
        } else {
          tracer <- quote(.Platform <- list(OS.type = os))
        }
        trace(R_user_dir, tracer = tracer)
        on.exit(untrace(R_user_dir))
      }
      R_user_dir("R.cache", which = "cache")
    })
    
    message("- R_user_dir('R.cache', which = 'cache'): ", sQuote(path_R))
    path_R <- normalizePath(path_R, mustWork = FALSE)
    message("- Normalized version: ", sQuote(path_R))
    res <- identical(path, path_R)
    message("- Identical to findOSCachePath(): ", res)
    if (!res) {
      message("- findOSCachePath() differ from R_user_dir(): ",
              sQuote(path), " != ", sQuote(path_R))
    }    
  }
} ## for (os ...)

message("findOSCachePath() ... done")