# apply to log()
try_expr(log(1))
try_expr(log(0))
try_expr(log(-1))
try_expr(log("a"))
# return a list where NULL if an error or warning appears
lapply(X = list("positive" = 1, "zero" = 0, "negative" = -1,"letter" = "a"),
FUN = function(x) {
log_try <- try_expr(log(x))
result <- log_try[["result"]]
warning <- log_try[["warning"]]
error <- log_try[["error"]]
if (!(is.null(error))) return(NULL)
if (!(is.null(warning))) return(NULL)
return(result)
})
Run the code above in your browser using DataLab