bash script - "Rscript: command not found" error
Solution 1
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
Solution 2
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.
Solution 3
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.
Related videos on Youtube
user12714
Updated on September 18, 2022Comments
-
user12714 over 1 year
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.-
smw about 8 years@MichaelDurrant /usr/bin/Rscript is provided by package r-base-core in Ubuntu, I believe
-
user12714 about 8 yearsthe 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
-
Michael Durrant about 8 yearsShould also probably be
Rscript ~/R/repetability.R
?
-
-
user12714 about 8 yearshi Michael, in this case R has been already installed.
-
Michael Durrant about 8 yearshmmm, 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. -
user12714 about 8 yearsMy 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 about 8 yearsHowever, 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.