# Divert standard output
pathname <- tempfile(fileext=".output.txt")
res <- withSink(file=pathname, {
print(letters)
})
mcat(readLines(pathname), sep="")
# Divert standard error/messages
pathname <- tempfile(fileext=".message.txt")
res <- withSink(file=pathname, type="message", {
mprint(LETTERS)
})
mcat(readLines(pathname), sep="")
Run the code above in your browser using DataLab