Search code examples
rqsub

for loop of subjobs using qsub R


I am trying to run subjobs (one for each chromosome) using R --vanilla. Since each chromosome is independent I want them to run parallel in the system. I have written the following script:

#!/bin/bash
for K in {20..21};
do 
qsub -V -cwd -b y -q short.q  R --vanilla --args arg1$K arg2$K arg3$K < RareMETALS.R > loggroup$K.txt; done

But somehow R opens interactively and not in command line as suppose... when trying the script itself

R --vanilla --args arg1 arg2 arg3 < RareMETALS.R > loggroup.txt; done

It runs perfectly calling the script.

Can someboby guide me, or point out which might be the problem.


Solution

  • My take on this would be to use echo instead of --args option to pass parameters to the script. I find separating the script and the Grid Engine code to be more straightforward:

    for K in {20..21};
    do 
        echo "Rscript RareMETALS.R arg1$K arg2$K arg3$K > loggroup$K.txt" | qsub -V -cwd -q short.q
    done
    

    As others have commented use Rscript.

    Code seems cleaner to me, but there may be some limitations to using echo as opposed to --args I am unaware of.