繁体   English   中英

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

[英]How to capture system2() output in 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”用于程序的“标准输出”。 这是程序用来识别程序“结果”的常用术语。

改用system

x <- system(paste(RR,'--version'), intern=TRUE)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM