【发布时间】:2020-03-30 02:09:38
【问题描述】:
tl;dr:如何从 R 控制台调用系统命令 y | conda create --name gee_interface,例如通过system2()?我对system2('conda', c('create', '--name', 'gee_interface')) 很满意,但我不知道如何通过system2() 处理'y' 中的管道。
详情
我正在尝试使用 R 控制台运行 bash 命令conda create --name gee_interface(安装了 Anaconda 的 OSX Mojave)。
在终端中,该命令执行得很好,但提示我回答 Proceed ([y]/n)?(我回答“y”,一切正常)。
在 R 中,我运行
Sys.setenv(PATH = paste(c("/Applications/anaconda3/bin", Sys.getenv("PATH")), collapse = .Platform$path.sep)) # ensures that system2() finds conda
system2('conda', c('create', '--name', 'gee_interface')) # This is the key line for the purposes of this question
当运行第二行时 [i.e. system2('conda', c('create', '--name', 'gee_interface'))],该过程永远不会完成,但会迅速降至零 CPU 使用率。大概系统正在等待我对提示的响应,但我不知道如何提供它。如何通过 R 脚本做到这一点?另请注意,在我的特定情况下,我需要响应“y”的次数是可变的,具体取决于名称为 gee_interface 的环境是否已经存在。
【问题讨论】:
标签: r