我正在尝试了解如何从system()
EX:
> res <- system("ls home",intern=TRUE)
ls: cannot access home: No such file or directory
Warning message:
running command 'ls home' had status 2
> res
character(0)
attr(,"status")
[1] 2
有没有办法在res
中捕获“ls:无法访问主页:没有这样的文件或目录”?
答案 0 :(得分:2)
尝试这样,即重定向stderr数据
res <- system("ls home 2>&1",intern=TRUE)
将导致
[1] "ls: home: No such file or directory"
attr(,"status")
[1] 1