在bash脚本中运行多个R脚本

时间:2019-06-10 12:08:59

标签: r bash shell

我有2个R脚本,分别称为script1.Rscript2.R,我想按管道顺序运行它们。为此,我正在尝试使bash脚本运行2个R脚本,使用输入和参数(对于每个脚本)并返回输出(对于每个脚本)。由于有2个R脚本,因此我们有2个步骤,如下所示: 1-这是第一个R脚本的命令:

Rscript script1.R /path/to/input /path/to/OutputDir argument1 argument2

2-这是第二个R脚本的命令:

Rscript script2.R /path/to/output_of_1st_script /path/to/OutputDir argument3 default_yes

要运行这两个R脚本,我制作了以下bash脚本,但未返回任何内容!你知道如何解决吗?

#!/bin/bash

set -e;
set -u;


OUTDIR1="./output1/";
OUTDIR2="./output2/";
INDIR="./input/";

argument1=$1;
argument2=$2;
argument3=$3;

mkdir ${OUTDIR1} || true;
#to run the 1st script
ls -1 ${INDIR}/*/inputfile.txt | sort -V | while read infile; do
    b=$(basename $(dirname "$infile"));

    ./script1.R \
        -v \
        run \
        -o "${of}" \
        -f 0 \
        argument1 \
        argument2 \
        "${b},${infile}" \
    ;
done

#to run the 2nd script. input of this sript is the output from previous script
ls -1 ${OUTDIR1}/*/output.txt | sort -V | while read outfile1; do
    b=$(basename $(dirname "$outfile1"));

    ./script1.R \
        -v \
        run \
        -o "${of}" \
        -f 0 \
        argument3 \
        "${b},${outfile1}" \
    ;
done

0 个答案:

没有答案
相关问题