0

I'm trying to get the output from a binary with args called by system2 into an R object. But, I fail. I've googled for several alternatives such as system, exec_internal but cannot get it right. Here is a toy example using Linux' function "factor" which should factorize 5555.

test_001 <- system2("factor", args=c("5555"))

and the output shown on the monitor is

5555: 5 11 101

However, I would like to have that result into the object "test_001". But if I type

test_001

the result is only

[1] 0

I really don't understand how to get the output from system2 into an R object. Thanks for any help!

4

1 回答 1

0

stdout您必须通过指定(并且可能etderr)选项来更改输出发送到的位置。由于 system2 的帮助表明默认输出是 R 控制台

应该发送到“stdout”或“stderr”的输出。可能的值是“”,对于 R 控制台(默认值)、NULL 或 FALSE(丢弃输出)、TRUE(在字符向量中捕获输出)或命名文件的字符串。

output = TRUE将输出作为 R 中的字符向量对象发送。因此,对于您的情况,您可以:

test_001 <- system2("factor", args=c("5555"), stdout = TRUE)
于 2017-07-26T11:14:38.610 回答