Question

I installed R under my home folder, and I would like to use the new R is invoked when I submit jobs to clusters. The cluster nodes all have CentOS installed.

Here is the configure I made in the .bash_profile and .bashrc:

if [ `lsb_release -i|cut -c17-20` == 'Cent' ] ; then
    alias R='/home/XXX/R-3.0.2/bin/R'
    alias Rscript='/home/XXX/R-3.0.2/bin/Rscript'
fi

I added following in .bash_profile:

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

I also added this to the scripts submitted.

source $HOME/.bash_profile

I tried with qsub -I, it works perfect.

However, after I submit the job, and which R still show the original path!

How to set the environment correctly?

Was it helpful?

Solution

Aliasing doesn't affect the which command, for example:

$ which R
/usr/bin/R
$ alias R=/bin/date
$ R
Sun Jan  5 13:40:54 CET 2014      # as you see the alias works
$ which R                         # `which R` still returns the original path
/usr/bin/R

Instead of using aliases, I think you want to prepend /home/XXX/R-3.0.2/bin to PATH:

PATH="/home/XXX/R-3.0.2/bin:$PATH"

After this, if R and Rscript exist in /home/XXX/R-3.0.2/bin, then:

  • which R should return /home/XXX/R-3.0.2/bin/R
  • which Rscript should return /home/XXX/R-3.0.2/bin/Rscript

as they will be found in /home/XXX/R-3.0.2/bin first, before any other directory in the rest of $PATH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top