Skip to content

Instantly share code, notes, and snippets.

Last active Nov 14, 2020
What would you like to do?
Load environment modules ( after R is started
# modify as needed
modules = c("git", "git-lfs", "gcc")
capt = system2("./", modules, stdout = TRUE)
split = strsplit(capt, '=', fixed = TRUE)
out = lapply(split, function(v){, stats::setNames(list(v[2]), v[1]))
message("Added environment variables for ", paste(modules, collapse = ', '))
module load $@
echo -n "PATH="
printenv PATH
echo -n "LD_LIBRARY_PATH="
# if other variables are set you might need add more echo and printenv statements

This comment has been minimized.

Copy link
Owner Author

@amcdavid amcdavid commented Nov 13, 2020

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. loads the modules and captures changes to PATH and LD_LIBRARY_PATH which are then manually set on the R process with Sys.setenv(). If done in .Rprofile, then this will have the same effect as if it were done before R was loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment