簡體   English   中英

混合bash和R命令

[英]Mixing bash and R commands

閱讀其他文章后,我似乎無法弄清楚如何成功地將bash和R命令混合使用。

我需要使用用戶定義的函數。 我的想法如下。

#!/bin/bash
#fasta conversion
#$ -N convert_fasta
#$ -o convert_fasta.stdout
#$ -e convert_fasta.stderr

module load R/3.4.0
input=/data/dir/path
output=/output/dir/path

#set output directory define function
setwd($output/)
convert <- function(fasta.file, file.name="phylip.phy"){...}

#bash loop to convert files
for file in `ls $input/*.fasta`
do
    convert($file,'$file.phy')
    echo '$file converted to .phy'
done

但是,這似乎不起作用。 任何幫助將不勝感激。

您可以嘗試以下操作,只需確保注意bash和R端的變量名稱即可。 \\ $ output被轉義以避免bash解釋它。 我留給您R和bash :)之間的交互作用,即,如果您想在bash端使用R值。

#!/bin/bash
#fasta conversion

RScript -e <<<EOFR
    module load R/3.4.0
    input=/data/dir/path
    output=/output/dir/path

    #set output directory define function
    setwd(\$output/)
    convert <- function(fasta.file, file.name="phylip.phy"){...}
EOFR

也請檢查此頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM