-
Notifications
You must be signed in to change notification settings - Fork 2
/
cache-dir.R
83 lines (70 loc) · 2.47 KB
/
cache-dir.R
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#' Root of the cache directory
#'
#' @return Path to the root of the cache directory,
#' determined using `rappdirs`. E.g. on macOS it is
#' `/Users/gaborcsardi/Library/Caches/R-crancache`.
#'
#' @importFrom rappdirs user_cache_dir
#' @export
get_cache_dir <- function() {
Sys.getenv(
"CRANCACHE_DIR",
user_cache_dir("R-crancache")
)
}
#' Get all package directories
#'
#' These are the directories that contain the packages.
#' There is a currently two of them:
#' * The `cran` directory contains binary and/or source packages,
#' downloaded and/or installed from CRAN.
#' * The `bioc` directory contains binary and/or source BioConducor
#' packages.
#' * The `other` directory contains non-CRAN packages.
#'
#' Each directory themself may contain multiple repositories,
#' according to the default layout by [utils::contrib.url()].
#'
#' @return A named character vector of package directories.
#' @export
get_cache_package_dirs <- function() {
cache_dir <- get_cache_dir()
cran <- file.path(cache_dir, "cran")
bioc <- file.path(cache_dir, "bioc")
other <- file.path(cache_dir, "other")
cran_bin <- file.path(cache_dir, "cran-bin")
bioc_bin <- file.path(cache_dir, "bioc-bin")
other_bin <- file.path(cache_dir, "other-bin")
c(
"cran-bin/source" = get_package_dirs(cran_bin, "source"),
"cran/platform" = get_package_dirs(cran, .Platform$pkgType),
"cran/source" = get_package_dirs(cran, "source"),
"bioc-bin/source" = get_package_dirs(bioc_bin, "source"),
"bioc/platform" = get_package_dirs(bioc, .Platform$pkgType),
"bioc/source" = get_package_dirs(bioc, "source"),
"other-bin/source" = get_package_dirs(other_bin, "source"),
"other/platform" = get_package_dirs(other, .Platform$pkgType),
"other/source" = get_package_dirs(other, "source")
)
}
#' @importFrom utils URLencode
get_cache_urls <- function(type = "both") {
repo_names <- if (type == "both" || type == "binary" ||
grepl("^mac.binary", type) || grepl("win.binary", type)) {
c("cran-bin", "cran", "bioc-bin", "bioc", "other-bin", "other")
} else {
c("cran", "bioc", "other")
}
paths <- paste0("file://", get_cache_dir(), "/", repo_names)
structure(
vapply(paths, URLencode, character(1), USE.NAMES = FALSE),
names = repo_names
)
}
#' @importFrom utils contrib.url
get_package_dirs <- function(root, type) {
paste0(
root,
vapply(type, contrib.url, "", repos = "")
)
}