【问题标题】:Invoking a UNIX command in R - join operation在 R 中调用 UNIX 命令 - 连接操作
【发布时间】:2015-07-13 11:15:55
【问题描述】:
system("join -o 1.2 <(sort new.txt) <(sort t.txt) > t20.txt;")

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `join -o 1.2 <(sort new.txt) <(sort t.txt) > t20.txt;'

我怎样才能正确地写这个?

【问题讨论】:

  • 您的报价似乎有问题。您想从命令行启动的命令到底应该是什么?
  • 我刚刚更正了这个问题。我想在 R 终端上调用连接操作。它适用于 bash 终端。
  • @nicola 对上述内容有什么想法吗?
  • 我猜问题来自system 使用sh 而您的线路需要bash。如果你把你的行放在一个文件中然后运行system("bash filename.sh") 它应该可以工作。
  • @nicola 我正在考虑用 R 代码附加这一行,所以我希望像这样运行它。

标签: r unix system


【解决方案1】:

正如@nicola 所说,您可以将该行放入文件并运行为:

system("bash filename.sh")

如果您想避免创建文件,可以在 bash 上使用 -c 选项,如下所示:

system("bash -c 'join -o 1.2 <(sort new.txt) <(sort t.txt) > t20.txt'")

您可以在this answer 中阅读有关-c 选项的更多背景信息。

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多