Reputation: 403
I have a R script (abc.R
):
#!/usr/bin/env Rscript
print("HELLO")
And a batch script containing the R script (example.sh
):
#!/bin/bash
module load Rstats
module load RstatsPackages
Rscript /home1/R_scripts/abc.R > "result.txt"
And another batch script (multiple.sh
), which calls the above script:
#!/bin/sh
for((i=1;i<=10;i++))
do
sbatch -p normal -t 4:00:00 -N 1 -n 4 example.sh $i
done
sh multiple.sh
This script calls the above script ten times that way my Rscript will be run 10 times. It is running 10 times, but it is generating only one result.txt. However, I want multiple result files like result1.txt
, result2.txt
, result3.txt
and so on.
Upvotes: 0
Views: 364
Reputation: 623
Since the iteration number ($i
) is passed as an argument to example.sh
from multiple.sh
, same can be used to create a file per iteration. To do so change last line of example.sh
to:
Rscript /home1/R_scripts/abc.R > "result${1}.txt"
Upvotes: 4