0

I help maintain an R package that auto-generates shell scripts for using Slurm to run Rscript on a remote server. There is a template for a submit.sh script that is filled in with arguments supplied by the user in an R function. However some systems are configured with environment modules so that the shell script needs to have the line module load R before Rscript is called.

Is there some logic I can execute from within R to detect whether module load R is necessary so that the line module load R is included in the shell script, conditional on whether or not it's necessary?

Link to the source code of our R package: rslurm
Template for submit.sh: submit.sh.txt

qdread
  • 3,389
  • 19
  • 36
  • You can check out the module documentation: https://modules.readthedocs.io/en/latest/module.html. You can use things like `module list` to see all currently loaded modules or `module is-loaded R` to see if the module is loaded. – MrFlick Jul 29 '21 at 19:32

1 Answers1

2

From the shell script, you may check if the module shell function is defined, then check if the R module exists in which case an attempt to load this module should be made:

type module >/dev/null 2>&1
if [ $? -eq 0 ] && module is-avail R; then
    module load R
fi

If the R module is already loaded, the module load command will do nothing. So it is safe to use it even if R module is already loaded.