Almost everything, but itโs quite complicated, and itโs rather annoying that, unlike standard output, the message output cannot be split, that is, redirected to a file and stored at the output at the same time (behavior in the UNIX tick)!
options(warn = 1) tmpSinkfileName <- tempfile() tmpFD <- file(tmpSinkfileName, open = "wt") sink(tmpFD, split = TRUE) sink(tmpFD, type = "message") cat("Doing something\n") warning("Hi here") cat("Doing something else\n") warning("Hi there") sink(type = "message") sink() console.out <- readChar(tmpSinkfileName, file.info(tmpSinkfileName)$size) unlink(tmpSinkfileName) cat(console.out)
If i try
sink(tmpFD, type = "message", split = TRUE)
it says
Error in the receiver (tmpFD, type = "message", split = TRUE): it is not possible to share the connection with the message
which is very annoying!
source share