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
From the shell script, you may check if the
moduleshell function is defined, then check if theRmodule exists in which case an attempt to load this module should be made:If the
Rmodule is already loaded, themodule loadcommand will do nothing. So it is safe to use it even ifRmodule is already loaded.