我需要使用R唤起一些shell命令。我还需要捕获该命令的输出(它输出到R控制台中)。不幸的是,capture.output无法正常工作。
> shell("test")
'test' is not recognized as an internal or external command,
operable program or batch file.
Warning message:
In shell("test") : 'test' execution failed with error code 1
我需要捕获这一部分:
'test' is not recognized as an internal or external command,
operable program or batch file.
你们中的任何人都知道如何解决该问题吗?
答案 0 :(得分:1)
只需使用intern = TRUE
:
out <- shell("test", intern = TRUE)
out
#[1] "'test' is not recognized as an internal or external command,"
#[2] "operable program or batch file."
#attr(,"status")
#[1] 1