I'm trying to run a function but get some knowledge of whether or not it completed successfully, issued an error or a warning, I've tried doing the following:
ret <- 0
tryCatch(expr = {
cat(non_existing_variable, "\n")
},
error = function(e) {
ret <- 1
cat("Got into error condition!\n")
},
warning = function(w) {
ret <- 2
cat("Got into warning condition!\n")
}
)
cat("ret =", ret, "\n")
But it prints:
Got into error condition!
ret = 0
I expected it to yield ret = 1.
What is happening here?