want to understand how to use tryCatch in R.
1. tryCatch(stop("!"), error = function(e) "An error")
[1] "An error"
Question: how does the function run? stop generates the error, but what's the use of following function 'error'? what is the meaning of argument 'e'?
2. show_condition <- function(code) { tryCatch(code, error = function(c) "error", warning = function(c) "warning", message = function(c) "message" ) }
show_condition(stop("!"))
[1] "error"
show_condition(warning("?!"))
[1] "warning"
show_condition(message("?"))
[1] "message"
Question: what's the meaning of 'c'? where is 'c' from? why the different return depends on the code?