Q:

How to capture console output in R language?

I'm running a script of R, and into this script I'm using the function system() to delete a directory, the problem is that sometimes I have a problem with it, and I need know what is the specific problem, but I don't have opened a console to verify, so how can I capture all of output, message, and exception that normally are in console, and may be redirect to file.
I'm trying with sink(), and capture.output() but I don't know why it doesn't work for me.
Example:
system("rm -r ../DirToDelete")
"capture message that throwing this function"

Thanks for all.

A:

See help(system) for details but setting intern may be all you need:
R> txt <- system("date", intern=TRUE)
R> txt
[1] "Tue Sep 24 10:08:23 CDT 2013"
R> 

As for removing files (and directories), see help(unlink).

