-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzzz.R
45 lines (39 loc) · 1.25 KB
/
zzz.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
STAGEDDEPS_FILENAME <- "staged_dependencies.yaml"
CONFIG_FILENAME <- "config.yaml" # staged.dependencies._storage_dir
# Use this function when you want to change the storage directory while the package is already loaded
# It does not delete the old storage directory
setup_storage_dir <- function(storage_dir) {
set_storage_dir(storage_dir)
# only copy config if storage dir does not exist
if (!dir.exists(storage_dir)) {
dir.create(storage_dir)
copy_config_to_storage_dir()
}
if (!dir.exists(get_packages_cache_dir())) {
dir.create(get_packages_cache_dir())
}
storage_dir
}
get_storage_dir <- function() {
options()$staged.dependencies._storage_dir
}
set_storage_dir <- function(storage_dir) {
options("staged.dependencies._storage_dir" = storage_dir)
}
.onLoad <- function(libname, pkgname) {
storage_dir <- getOption(
"staged.dependencies._storage_dir",
path.expand("~/.staged.dependencies")
)
op <- options()
op.package <- list(
# mapping from hosts to
staged.dependencies.token_mapping = c(
"https://github.com" = "GITHUB_PAT",
"https://gitlab.com" = "GITLAB_PAT"
)
)
toset <- !(names(op.package) %in% names(op))
if (any(toset)) options(op.package[toset])
setup_storage_dir(storage_dir)
}