3

I have the following bash script trying to run it in Linux but I receive an error message that line 31: Rscript: command not found. Can you please give me an advice if where I am wrong?

#!/bin/bash
#PBS -S /bin/bash
#PBS -N garunsmodel
#PBS -l mem=10g
#PBS -l walltime=02:00:00
#PBS -A improvingherds
#PBS -m ae


nodeDir=`mktemp -d /tmp/phuong.XXXXX`

cp -r /group/dairy/phuongho/garuns $nodeDir

cd $nodeDir

cd garuns
module load gcc vle // this is to load vle platform
rm -rf out
mkdir out

#In garuns.vpz. The output file path has to be changed.
#to an absolute path that's available on the node the script is running.

XXX=`pwd`
sed -i "s|/group/dairy/phuongho/garuns/out|$XXX/out/|" exp/garuns.vpz
Rscript  R/repetability.R

DATE=`date +%Y%m%d-%H%M%S`
mkdir "/group/dairy/phuongho/job.$DATE"

cp -r out  "/group/dairy/phuongho/job.$DATE"

When I tried to access manually to tmp/phuong.XXXXX/garuns then run R, it worked just fine.

3
  • @MichaelDurrant /usr/bin/Rscript is provided by package r-base-core in Ubuntu, I believe Feb 15 '16 at 22:59
  • the file named: repetability.R contain all R commands needed to run the model garuns above. So, I am not sure if we have to specify anything. The repetability.R lives in: /garuns/R/repetability.R Thanks
    – user12714
    Feb 15 '16 at 23:00
  • Should also probably be Rscript ~/R/repetability.R? Feb 15 '16 at 23:12
3

If R has already been installed, it could be that the PATH variable picks up the wrong RScript? Check with which RScript

In this case try export PATH=/path/to/alternate/r/bin:$PATH Or try brute-forcing by giving the absolute path when referencing RScript, e.g. ~/R-3.2.5_patched/bin/RScript/R/repetability.R

1

This looks like a script that is submitted to a compute cluster through something like SLURM. You should talk to your system's administrator and ask whether R is installed on the cluster and if so, how to enable access to it in your script.

On the clusters I have access to, some software will need to be loaded with a module load somesoftware/version command, which updates/sets the environment variables needed to run the software.

1

I fixed this by replacing Rscript in my bash script with /usr/local/bin/Rscript (or wherever your Rscript is located - do which Rscript to find out). Explicitly adding it to my PATH as suggested in other answers made no difference.

0

You need to install R

For example on Ubuntu:

sudo apt-get install r-base-core

Then the Rscript command will be recognized at the command line.

I did this and it worked but be aware that the install was pretty massive with hundreds of dependencies installed. Took a few minutes to install.

4
  • hi Michael, in this case R has been already installed.
    – user12714
    Feb 15 '16 at 23:07
  • hmmm, when I put it in a file it recognizes the command, e.g. $ cat x.sh Rscript x.R $ ./x.sh Fatal error: cannot open file 'x.R': No such file or directory - can't open file but Rscript command itself was recognized. Feb 15 '16 at 23:10
  • My actual situation is that, I have a model called garuns with all source codes are written in the folder garuns above. To run this, we designed an Rscript which contain command for running garuns model as well as some calculations from the output. On my local directory, I can easily run this model by cd to garuns, then run: Rscript R/repetability.R (this works perfectly).
    – user12714
    Feb 15 '16 at 23:16
  • However, I now want to not run this on my local directory but on the cluster of our faculty. As you can see from the code above: I first need to copy on garuns folder to a tmp folder on the computer node, then from there I cd to garuns, then start running R as when I am on local directory. On cluster, the IT guys have installed R, as well as the vle package that I need. So I can not figure out what is the problem here.
    – user12714
    Feb 15 '16 at 23:16
0

I got the same error message but for a different reason. Posting it here as people will land here like I did too.

Check your first line is #!/bin/bash (which isn't your problem) rather than #!/bin/sh, else some commands like module load <> won't run.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.