r - 如何在 R 中捕获 system2() 输出

标签 r

下面是一个例子:

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/

相关文章:

r - 如何跟踪从 R 中生成的 word .docx 文件的更改

r - Shiny 的 react 性 ggplot 输出

r - 将因子分数添加到原始数据集

r - 从条件面板获取输入值

r - 是什么阻止添加当前的 R 保留字/符号集?

r - 如何在列表列表中对向量进行子集

r - ggplot::geom_boxplot() 如何更改 R 中一个框组的宽度

r - 在 R 的 matplot 中写入 $^*$

mysql - 在 R 中显示从 MySQL 检索到的日语字符

r - 读取大型 Excel xlsx 文件的最快方法?并行化与否?