0

I am trying to run an R script.

These are some lines from my R script big2.r

dataa <- read.csv("/home/people/R2/big2.csv")
write.csv(head(dataa), file="/home/people/R2/head.csv")

when I execute R CMD BATCH big2.r in the terminal, it gives me an .Rout file together with the head.csv.

But when I try that using my big2.sh file by submitting the job to the queue using qsub big2.sh It doesn't give me a .Rout file or the head.csv and the qstat for that job is C standard and then it's gone.

This is the content of my .sh file

#!/bin/bash -l

module load R/3.2.2
R CMD BATCH big2.r

What am I doing wrong? What is the proper way to submit a job which executes an R script?

When I try #!/usr/bin/r I get the following error.

-bash: /var/spool/torque/mom_priv/jobs/363059.sonic-head.SC: /usr/bin/r: bad interpreter: No such file or directory

I tried the solution found in Bash script: bad interpreter, but did not help.

Community
  • 1
  • 1
andy
  • 643
  • 2
  • 12
  • 20
  • 1
    Possible duplicate of [How to run R codes inside shell script?](http://stackoverflow.com/questions/24642281/how-to-run-r-codes-inside-shell-script) – Hack-R May 12 '16 at 21:24
  • Hi Hack-R, the solutions provided in that link do not solve my issue :( – andy May 12 '16 at 21:47
  • Have you tried? There's nothing special about the situation as you've described it and the example you provided doesn't follow the solution. Based on the edit you made to your question and the associated error I'd say you need to verify the location and / or try putting the path to Rscript on the first line like `#!/usr/bin/Rscript`. – Hack-R May 12 '16 at 22:00
  • May I ask how to find the path for r or Rscript? #!/usr/bin/Rscript or #!/usr/bin/r gives me the error "-bash: /var/spool/torque/mom_priv/jobs/363059.sonic-head.SC: /usr/bin/r: bad interpreter: No such file or directory" – andy May 12 '16 at 22:07

2 Answers2

1

Ok try something like this:

#!/usr/bin/bash -l
#PBS -N qsub_R_test

cd $PBS_O_WORKDIR
echo We are now in working directory $PWD
module load R/3.2.2
R CMD BATCH big2.r
Sudhir
  • 166
  • 7
  • "#!/usr/bin/bash -l" gives me -bash: /var/spool/torque/mom_priv/jobs/363068.sonic-head.SC: /usr/bin/bash: bad interpreter: No such file or directory – andy May 12 '16 at 23:01
  • put your own bash path there – Sudhir May 12 '16 at 23:02
  • thanks so much Sudhir, I am ashamed to say, I haven't seen the .rout file or the head.csv because they were created in the home directory. You did a great job. Thank you sooo much :) – andy May 12 '16 at 23:26
-1

You can create a shell script with something like (batchR.sh):

#!/bin/bash
#$ -S (your parameter can go here, one line for each)
#$ -j xyz

module load R/3.2.2 #in case you specifically need to load R on server node
R CMD BATCH big2.r

Submit this as qsub batchR.sh

Sudhir
  • 166
  • 7
  • hi Sudhir, when I use #!/bin/bash instead of #!/bin/bash -l, I get the following error : init.c(379):ERROR:109: Unknown shell type 'load' /var/spool/torque/mom_priv/jobs/363060.sonic-head.SC: line 4: R: command not found – andy May 12 '16 at 21:45
  • oh, my mistake. Are you providing the arguments for the queue in the .sh file? qsub will read the arguments for job submission like memory , which que etc. So, whichever argument you need to specify for queue submission, put them at the top of .sh file after #!/bin/bash as a comment (#$) – Sudhir May 12 '16 at 21:56
  • Sudhir may I ask you a different question?, if I want to switch from working node to high mem node it's stated that I have to mention that in PBS, I know the node name, how am I suppose to mention that using #PBS ? I know #PBS -l can be used for number of nodes & processors per node. But this is name of node – andy May 12 '16 at 22:03
  • sorry no idea about that... but as this is a totally different question, it would be better to put as new...and if this questions is solved please accept the answer that worked... – Sudhir May 12 '16 at 22:13
  • its ok Sudhir, but the answer you gave did not solve my prob :( – andy May 12 '16 at 22:19
  • how about what Hack-R suggesting? – Sudhir May 12 '16 at 22:23
  • I cnt use #!/usr/bin/Rscript or #!/usr/bin/r as it gives me the error "-bash: /var/spool/torque/mom_priv/jobs/363059.sonic-head.SC: /usr/bin/r: bad interpreter: No such file or directory" Do you know how to find the path for r or Rscript? – andy May 12 '16 at 22:25
  • to find R path with echo your $PATH or try which R – Sudhir May 12 '16 at 22:28
  • which R gives me "/opt/software/R/3.2.2/bin/R" and when I use #!/opt/software/R/3.2.2/bin/R instead of #!/bin/bash -l, I get "Fatal error: you must specify '--save', '--no-save' or '--vanilla' " – andy May 12 '16 at 22:33
  • you need to provide bash as well as R path – Sudhir May 12 '16 at 22:35
  • #!/bin/bash -l in first line and #!/opt/software/R/3.2.2/bin/R as the second? It gives me the same error – andy May 12 '16 at 22:36
  • just to confirm, how are you running your .sh file? – Sudhir May 12 '16 at 22:41