user2763361
user2763361

Reputation: 3919

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?

Upvotes: 3

Views: 9936

Answers (2)

Ricardo Oliveros-Ramos
Ricardo Oliveros-Ramos

Reputation: 4349

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

Upvotes: 2

Dirk is no longer here
Dirk is no longer here

Reputation: 368261

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.

Upvotes: 1

Related Questions