【问题标题】:How do I run system executables with aliases within R?如何在 R 中运行带有别名的系统可执行文件?
【发布时间】:2018-07-31 10:24:47
【问题描述】:

假设,我在 R 中运行系统命令来运行 executable

inputfile <- "/path/myfile.txt"

如何将以下命令中的/path/myfile.txt 替换为inputfile,如下面的命令所示?

system ("executable -input inputfile -output output.txt")

【问题讨论】:

    标签: r path system alias


    【解决方案1】:

    尝试以下任何一种:

    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")。该命令自动生成输出文件。
    • 问题是 如何将以下命令中的 /path/myfile.txt 替换为如下命令所示的 inputfile? 并且显示的代码确实可以做到这一点。完全不清楚您的第二个示例中有什么区别,但是如果您想用 /path/myfile.txt 替换 inputfile ,那么它会以同样的方式完成。
    • 这里不一定相关,但我建议(对 OP)你用shQuote 或至少sQuote 等进行防御。 (R 的systemsystem2 很破,也许sys 包更好。想法,G?)
    猜你喜欢
    • 1970-01-01
    • 2019-12-05
    • 2018-08-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多