这是一个例子:

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/

10-12 20:10