Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running R script through qsub

I am trying to run an R script called test.r through qsub. My R script is as follows:

#!/usr/bin/Rscript
x <- 1
write.csv(x,"test.csv")

If in Ubuntu terminal I type R CMD BATCH test.r, then the script behaves as planned; test.csv gets exported in the same directory.

However if I create a bash script called testbash.sh and run it through the command qsub testbash.sh; it will run without errors but the output won't be there.

#!/usr/bin/bash
R CMD BATCH test.r

How to fix this?

like image 979
user2763361 Avatar asked Jun 09 '26 03:06

user2763361


2 Answers

Try modifying your R script to:

#!/usr/bin/Rscript
x <- 1
print(getwd())
write.csv(x,"test.csv")

When you run a script via qsub, the script is normally running in another server, and by default as in your home directory. You need to change to the original directory in your script, there is a variable PBS_O_WORKDIR for that:

#!/usr/bin/bash
#PBS -N qsub_R_test
echo We are in the $PWD directory
cd $PBS_O_WORKDIR
echo We are now in $PBS_O_WORKDIR, running an R script.
R --vanilla < test.r > test.log 2> test.log

I normally cannot use R CMD BATCH, but redirection to R -vanilla works. You can also specify options for the PBS in the script, starting with #PBS, like the job name in this case (qsub_R_test).

You can get a more detailed list of qsub parameters here: http://www.csc.fi/english/pages/louhi_guide/batch_jobs/commands/qsub

And an example of a PBS script here: http://bose.utmb.edu/Compu_Center/Cluster_users/PBS%20HOWTO/PBS_HOW_TO.html

like image 166
Ricardo Oliveros-Ramos Avatar answered Jun 10 '26 18:06

Ricardo Oliveros-Ramos


You may be doing it wrong. If you have a shebang line like

#!/usr/bin/Rscript

then "simply" do chmod 0755 test.r on the file, and run it:

./test.r

That should work, and you can then have that invocation in your qsub-called script.

like image 35
Dirk Eddelbuettel Avatar answered Jun 10 '26 19:06

Dirk Eddelbuettel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!