Last active
August 1, 2024 19:58
-
-
Save amcdavid/f25fe3861c35b4ae40470ac25a378da4 to your computer and use it in GitHub Desktop.
Load environment modules (https://modules.readthedocs.io/en/latest/index.html) after R is started
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local({ | |
# modify as needed | |
modules = c("git", "git-lfs", "gcc") | |
capt = system2("./capture_module_environment.sh", modules, stdout = TRUE) | |
split = strsplit(capt, '=', fixed = TRUE) | |
out = lapply(split, function(v){ | |
do.call(Sys.setenv, stats::setNames(list(v[2]), v[1])) | |
}) | |
message("Added environment variables for ", paste(modules, collapse = ', ')) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
module load $@ | |
echo -n "PATH=" | |
printenv PATH | |
echo -n "LD_LIBRARY_PATH=" | |
printenv LD_LIBRARY_PATH | |
# if other variables are set you might need add more echo and printenv statements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rstudio-server generally doesn't inherit the environment of the calling shell. On systems that use environment modules to select among available software, rstudio server won't "see" software that was loaded with the modules.
capture_module_environment.sh
loads the modules and captures changes to PATH and LD_LIBRARY_PATH which are then manually set on the R process withSys.setenv()
. If done in .Rprofile, then this will have the same effect as if it were done before R was loaded.