Skip to content

Commit c3dae04

Browse files
committed
Make 01_setup_native.sh actually fail on partial install failure
install.packages() failing for one package doesn't make Rscript exit non-zero -- it just warns and continues -- so set -euo pipefail never caught it, and the script printed "Setup complete" unconditionally regardless of whether packages actually installed. Observed on Monsoon: RcppEigen got OOM-killed under a low default srun --pty bash allocation (no explicit --mem), which cascaded to ranger/reticulate/CodeCarbonR itself all failing to install, and the script still reported success. Now verifies installed.packages()/pandoc_available()/CodeCarbonR's own namespace explicitly after each install step and stop()s (which does exit non-zero) with a clear message if anything's still missing.
1 parent b54a4a6 commit c3dae04

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

hpc/monsoon/01_setup_native.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,46 @@ echo
4444
echo "=== R packages -> $RLIBS_DIR ==="
4545
mkdir -p "$RLIBS_DIR"
4646
export R_LIBS_USER="$RLIBS_DIR"
47+
# install.packages() failing for one package doesn't make Rscript exit
48+
# non-zero -- it just warns and moves on -- so `set -euo pipefail` alone
49+
# won't catch a partial failure here. Verify explicitly and stop() (which
50+
# does exit non-zero) if anything's still missing after the install
51+
# attempt. A package needing real memory to compile (RcppEigen
52+
# especially -- observed OOM-killed under a low default `srun --pty bash`
53+
# allocation with no explicit --mem) is exactly the kind of failure this
54+
# guards against silently sailing past.
4755
Rscript -e '
4856
options(repos = c(CRAN = "https://cloud.r-project.org"))
4957
needed <- c("rmarkdown", "knitr", "reticulate", "ranger", "dplyr",
5058
"tidyr", "readr", "testthat", "roxygen2", "remotes")
5159
have <- rownames(installed.packages())
5260
missing <- setdiff(needed, have)
5361
if (length(missing) > 0) install.packages(missing)
62+
still_missing <- setdiff(needed, rownames(installed.packages()))
63+
if (length(still_missing) > 0) {
64+
stop(
65+
"Failed to install: ", paste(still_missing, collapse = ", "),
66+
". Common cause: not enough memory to compile a package (RcppEigen ",
67+
"especially) -- rerun with more memory, e.g. `srun --mem=8G ",
68+
"--cpus-per-task=4 --pty bash` instead of a bare `srun --pty bash`.",
69+
call. = FALSE
70+
)
71+
}
5472
# Pandoc via a plain download, not conda -- rmarkdown needs it, and this
5573
# sidesteps the same conda issue this whole script exists to avoid.
5674
if (!rmarkdown::pandoc_available()) rmarkdown::install_pandoc()
57-
cat("pandoc:", if (rmarkdown::pandoc_available()) "OK" else "MISSING", "\n")
75+
if (!rmarkdown::pandoc_available()) stop("pandoc install failed.", call. = FALSE)
76+
cat("pandoc: OK\n")
5877
'
5978

6079
echo
6180
echo "=== Installing CodeCarbonR itself from this clone ==="
6281
Rscript -e '
6382
options(repos = c(CRAN = "https://cloud.r-project.org"))
6483
install.packages(".", repos = NULL, type = "source")
84+
if (!requireNamespace("CodeCarbonR", quietly = TRUE)) {
85+
stop("CodeCarbonR install failed -- see the install.packages() output above.", call. = FALSE)
86+
}
6587
'
6688

6789
echo

0 commit comments

Comments
 (0)