I found this very helpful factory to convert any function into a function that capture its values, errors, and warnings (How do I save warnings and errors as output from a function?):
factory <- function(fun)
function(...) {
warn <- err <- NULL
res <- withCallingHandlers(
tryCatch(fun(...), error=function(e) {
err <<- conditionMessage(e)
NULL
}), warning=function(w) {
warn <<- append(warn, conditionMessage(w))
invokeRestart("muffleWarning")
})
list(res, warn=warn, err=err)
}
My problem is that errors/warnings are also shown on screen (on top of being captured by the factory). How can I change it so that errors/warnings do not show on screen? Thanks