forked from remindmodel/remind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rprofile
101 lines (85 loc) · 4.07 KB
/
.Rprofile
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local({
# setting RENV_PATHS_LIBRARY ensures packages are installed into renv/library
# for some reason this also has implications for symlinking into the global cache
Sys.setenv(RENV_PATHS_LIBRARY = "renv/library")
# do not check if library and renv.lock are in sync, because normally renv.lock does not exist
options(renv.config.synchronized.check = FALSE)
# always set the renv project to the current directory
Sys.setenv("RENV_PROJECT" = getwd())
# when increasing renvVersion first commit new version's activate script and
# put that commit's hash into the git checkout call below
renvVersion <- "1.0.7"
# reset renv/activate.R to match renv 1.0.7
gitRoot <- system2("git", c("rev-parse", "--show-toplevel"), stdout = TRUE)
if (Sys.getenv("RESET_RENV_ACTIVATE_SCRIPT", unset = "TRUE") == "TRUE" &&
normalizePath(gitRoot) == normalizePath(".")) {
system2("git", c("checkout", "b83bb1811ff08d8ee5ba8e834af5dd0080d10e66", "--", "renv/activate.R"))
}
source("renv/activate.R")
if (packageVersion("renv") != renvVersion) {
renvLockExisted <- file.exists(renv::paths$lockfile())
renv::install(paste0("renv@", renvVersion))
if (!renvLockExisted) {
unlink(renv::paths$lockfile())
}
}
if (!"https://rse.pik-potsdam.de/r/packages" %in% getOption("repos")) {
options(repos = c(getOption("repos"), pik = "https://rse.pik-potsdam.de/r/packages"))
}
# bootstrapping, will only run once after remind is freshly cloned
if (isTRUE(rownames(installed.packages(priority = "NA")) == "renv")) {
message("R package dependencies are not installed in this renv, installing now...")
renv::install("rmarkdown", prompt = FALSE) # rmarkdown is required to find dependencies in Rmd files
renv::hydrate(prompt = FALSE, report = FALSE) # auto-detect and install all dependencies
message("Finished installing R package dependencies.")
}
# bootstrapping python venv, will only run once after remind is freshly cloned
if (!dir.exists(".venv/")
&& (Sys.which("python3") != ""
|| (Sys.which("python.exe") != ""
&& suppressWarnings(isTRUE(startsWith(system2("python.exe", "--version", stdout = TRUE), "Python 3")))
))) {
message("Python venv is not available, setting up now...")
# use system python to set up venv
if (.Platform$OS.type == "windows") {
system2("python.exe", c("-mvenv", ".venv"))
pythonInVenv <- normalizePath(file.path(".venv", "Scripts", "python.exe"), mustWork = TRUE)
} else {
system2("python3", c("-mvenv", ".venv"))
pythonInVenv <- normalizePath(file.path(".venv", "bin", "python"), mustWork = TRUE)
}
# use venv python to install dependencies in venv
system2(pythonInVenv, c("-mpip", "install", "--upgrade", "pip", "wheel"))
system2(pythonInVenv, c("-mpip", "install", "-r", "requirements.txt"))
}
# Configure locations of REMIND input data
# These can be located in directories on the local machine, remote directories,
# or default directories on the cluster.
# To use these, set the environment variable in your ~/.bashrc file in your home
# direcotry (on linux) or in the system environment variables dialog (on windows):
# local directories
# e.g.
# on Linux (separate multiple paths by colons)
# REMIND_repos_dirs="/my/first/path:/my/second/path"
# on Windows (separate multiple paths by semicolons)
# REMIND_repos_dirs="C:\my\first\path;D:\my\second\path"
remindReposDirs <- Sys.getenv("REMIND_repos_dirs")
# unless specified otherwise, use cluster defaults
use_cluster_defaults <- TRUE
# add local directories, if any
if ("" != remindReposDirs) {
directories <- unlist(strsplit(remindReposDirs, .Platform$path.sep, fixed = TRUE))
directoriesList <- rep(list(NULL), length(directories))
names(directoriesList) <- directories
options(remind_repos = c(options("remind_repos")[[1]], directoriesList))
use_cluster_defaults <- FALSE
}
# Include local calibration results, if they exist, from either the main
# directory or output directories.
path <- file.path(
c('.', file.path('..', '..')),
'calibration_results', '.Rprofile_calibration_results')
path <- head(path[file.exists(path)], 1)
if (!rlang::is_empty(path))
source(path)
})