从R 2.15开始,
system2当
stdout和/或
stderr为TRUE 时,会将返回值作为属性给出。这使获取文本输出和返回值变得容易。
在此示例中,
ret最终是带有属性的字符串
"status":
> ret <- system2("ls","xx", stdout=TRUE, stderr=TRUE)Warning message:running command ''ls' xx 2>&1' had status 1 > ret[1] "ls: xx: No such file or directory"attr(,"status")[1] 1> attr(ret, "status")[1] 1


