【发布时间】:2018-07-31 10:24:47
【问题描述】:
假设,我在 R 中运行系统命令来运行 executable。
inputfile <- "/path/myfile.txt"
如何将以下命令中的/path/myfile.txt 替换为inputfile,如下面的命令所示?
system ("executable -input inputfile -output output.txt")
【问题讨论】:
假设,我在 R 中运行系统命令来运行 executable。
inputfile <- "/path/myfile.txt"
如何将以下命令中的/path/myfile.txt 替换为inputfile,如下面的命令所示?
system ("executable -input inputfile -output output.txt")
【问题讨论】:
尝试以下任何一种:
library(gsubfn)
fn$system("executable -input $inputfile -output output.txt")
或者没有包:
cmd <- sprintf("executable -input %s -output output.txt", inputfile)
system(cmd)
【讨论】:
system ("plink --bfile inputfile --freq")。该命令自动生成输出文件。
shQuote 或至少sQuote 等进行防御。 (R 的system 和system2 很破,也许sys 包更好。想法,G?)