Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
@MichaelDurrant /usr/bin/Rscript is provided by package r-base-core in Ubuntu, I believe – steeldriver 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? – Michael Durrant Feb 15 '16 at 23:12

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.

share|improve this answer
    
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. – Michael Durrant 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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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