I am trying to capture complete console log of my R script. I want a chronological order of everything, warnings printed as they occur. I tried this:
options(warn = 1)
tmpSinkfileName <- tempfile()
sink(tmpSinkfileName, split = TRUE)
cat("Doing something\n")
warning("Hi here")
cat("Doing something else\n")
warning("Hi there")
sink()
console.out <- readChar(tmpSinkfileName, file.info(tmpSinkfileName)$size)
unlink(tmpSinkfileName)
cat(console.out)
# Doing something
# Doing something else
warnings()
# NULL
but unfortunatelly the warnings are missing in console.out
. How can I do this? According to the docs, options(warn = 1)
should print the warnings as they occur. Unfortunatelly, they were not captured by sink()
.