下面是一个例子:
RR<-"/usr/bin/R"
x<-system2(RR, "--version")
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.
> x
[1] 0
正如你在这里看到的
x is 0
.我的问题是如何将 'system2(RR, "--version")' 输出分配给 x
.
最佳答案
这在 ?system2
的文档中有所描述。 .如果要将程序的输出捕获为字符向量,请设置 stdout=TRUE
x <- system2(RR, "--version", stdout=TRUE)
“stdout”用于程序的“标准输出”。这是程序用来标识程序的“结果”的常用术语。
关于r - 如何在 R 中捕获 system2() 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42681988/