withStopMessage | R Documentation |
Execute an expression and print an error message if it fails
withStopMessage(expr)
expr |
The expression to execute |
The result of the expression
f <- function(expr) {
val <- try(expr, silent = TRUE)
err <- if (inherits(val, "try-error")) attr(val, "condition") else NULL
if (!is.null(err)) value <- NULL
list(value = val, error = err)
}
ret <- f(log("a")) # this error will not show up in the console
ret <- f(withStopMessage(log("a"))) # this error will show up in the console
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.