How to correctly log warnings and errors using `tryCatch` in R?
问题 I have a function fun that often produces warnings and occasionally throws errors. I am trying to use tryCatch to log warnings and errors, as suggested in this answer. How can I simultaneously store the warnings and errors? Here is a minimal setup: # Function for warnings, errors. fun <- function(i) { # Print warnings as they come in. options(warn = 1) # Issue warning. warning(paste("Warn.", i)) # Stop. if(i == 3) { stop(paste("Err.", i)) } # Restore warning default behaviour. options(warn =