Reputation: 373
I am trying to find out how to capture the error message from 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
Is there a way to capture the "ls: cannot access home: No such file or directory" in res
?
Upvotes: 2
Views: 1803
Reputation: 35428
Try it like that, i.e. redirecting the stderr data
res <- system("ls home 2>&1",intern=TRUE)
which will result in
[1] "ls: home: No such file or directory"
attr(,"status")
[1] 1
Upvotes: 3