0

I have multiple R scripts to read (up to 3 i.e. tr1.R, tr2.R, tr3.R).
The bash script for reading a single script is given below

#!/bin/bash
#PBS -l nodes=1:ppn=10,walltime=00:05:00
#PBS -M 
#PBS -m e
module load R/4.0
Rscript ~/tr1.R

I tried the following as suggested by @cas

#!/bin/bash
#PBS -l nodes=1:ppn=10,walltime=00:05:00
#PBS -M 
#PBS -m e
module load R/4.0
**Rscript ~/tr"$i".R**

Further, the job is submitted using

for i in {1..3} ; do
  qsub -o "default.$i.out" -e "errorfile$i" -v i script.sh
done

This couldnot read Rscript ~/tr"$i".R.

b_takhel
  • 21
  • 4

2 Answers2

0

This is quick and dirty:

#!/bin/bash

echo -e "Printing script.......\n"

y=0
for (( y=0; y <= 9; y++ ))
do
   echo "file tr$y.R contents: "
   cat tr$y.R
   echo ""   
done
Shōgun8
  • 695
  • 5
  • 16
0

How about solving that in R like this,

combined.R:

source (tr1.R)
source (tr2.R)
source (tr3.R)

or like this.

combined.R:

for (i in c(1:9)) {
    filename <- paste ("tr", i, ".R", sep="")
    if (file.exists (filename)) {
        source (filename)
    }
}

And then you can load combined.R:

#!/bin/bash
#PBS -l nodes=1:ppn=10,walltime=00:05:00
#PBS -M 
#PBS -m e
module load R/4.0
Rscript ~/combined.R

Oh, I see now that you want to run jobs in paralell. The solution I posted does not run jobs in paralell, but I will leave the answer here. Maybe somebody will find it useful. Maybe you can apply something like this https://www.blasbenito.com/post/02_parallelizing_loops_with_r/ or this https://stackoverflow.com/questions/38318139/run-a-for-loop-in-parallel-in-r.

nobody
  • 1,545
  • 12
  • 19