Repository navigation
Expand file tree
/
Copy pathinstall_packages.R
More file actions
127 lines (115 loc) · 3.91 KB
/
Copy pathinstall_packages.R
File metadata and controls
127 lines (115 loc) · 3.91 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# =============================================================================
# install_packages.R
# Install project R packages into the personal HiPerGator library on /blue.
#
# Before running:
# 1. Load the R and spatial-library modules used by the project.
# 2. Run with that same R version/environment when running the pipeline.
#
# Run:
# Rscript install_packages.R
# =============================================================================
lib_path <- "/blue/ewhite/alexanderblochel/R/libs"
if (!dir.exists("/blue")) {
stop("This installer is intended for HiPerGator: /blue was not found.")
}
if (!dir.create(lib_path, recursive = TRUE, showWarnings = FALSE) &&
!dir.exists(lib_path)) {
stop("Could not create R library directory: ", lib_path)
}
if (file.access(lib_path, 2) != 0) {
stop("R library directory is not writable: ", lib_path)
}
.libPaths(c(lib_path, .libPaths()))
cat("R version: ", R.version.string, "\n", sep = "")
cat("Library: ", normalizePath(lib_path), "\n", sep = "")
cat("Library paths:\n")
print(.libPaths())
# Remove any stale lock files that could block installation
stale_locks <- list.files(lib_path, pattern = "^00LOCK", full.names = TRUE)
if (length(stale_locks) > 0) {
cat("\nRemoving stale lock files:\n")
for (lock in stale_locks) {
cat(" ", lock, "\n")
unlink(lock, recursive = TRUE)
}
}
# Use CRAN source packages. This avoids selecting binaries for an OS that may
# not match the HiPerGator compute environment. Source installation requires
# available compilers and compatible system libraries.
cran_repo <- "https://cloud.r-project.org"
options(repos = c(CRAN = cran_repo))
# fs requires libuv; use the bundled static version on HiPerGator
Sys.setenv(USE_BUNDLED_LIBUV = 1)
cran_packages <- c(
# Core data
"digest", "dplyr", "tidyr", "readr", "tsibble", "zoo",
# Visualization
"ggplot2", "patchwork", "stringr", "glue", "ggExtra", "ggside", 'pdftools',
# Modeling
"mvgam", "distributional", "verification", "fable", "feasts",
# Parallel
"future", "furrr", "progressr",
# Configuration and utilities
"config", "conflicted", "remotes", "fs", "devtools",
# Spatial
"sf", "stars", "units", "terra"
)
cat("\nInstalling CRAN packages into ", lib_path, "...\n", sep = "")
install.packages(
cran_packages,
lib = lib_path,
repos = cran_repo,
Ncpus = 1
)
# cmdstanr is distributed through the Stan r-universe, with CRAN as a
# fallback for dependencies. This does not install CmdStan itself.
cat("\nInstalling cmdstanr...\n")
install.packages(
"cmdstanr",
lib = lib_path,
repos = c(
"https://stan-dev.r-universe.dev",
CRAN = cran_repo
),
Ncpus = 1
)
# These GitHub packages are installed from source.
cat("\nInstalling edenR from GitHub...\n")
remotes::install_github(
"weecology/edenR",
lib = lib_path,
dependencies = TRUE,
upgrade = "never"
)
cat("\nInstalling wader from GitHub...\n")
remotes::install_github(
"weecology/wader",
lib = lib_path,
dependencies = TRUE,
upgrade = "never"
)
cat("\nInstalling fable.gam from GitHub...\n")
remotes::install_github(
"hendersontrent/fable.gam",
lib = lib_path,
dependencies = TRUE,
upgrade = "never"
)
# Confirm installation and test that the key packages can be loaded.
requested_packages <- c(cran_packages, "cmdstanr", "edenR", "wader", "fable.gam")
installed <- rownames(installed.packages(lib.loc = lib_path))
missing <- setdiff(requested_packages, installed)
if (length(missing) > 0) {
cat("\nPackages missing from ", lib_path, ":\n", sep = "")
cat(paste0(" - ", missing, collapse = "\n"), "\n")
stop("Some requested packages were not installed.")
}
cat("\nTesting package loads...\n")
for (pkg in requested_packages) {
cat(" ", pkg, ": ", sep = "")
loadNamespace(pkg, lib.loc = lib_path)
cat("OK\n")
}
cat("\nAll requested packages are installed and load in:\n", lib_path, "\n", sep = "")
cat("Note: cmdstanr is installed, but CmdStan itself must be installed separately.\n")