View source: R/handle_conditions.R
handle_conditions | R Documentation |
Handle conditions
handle_conditions(expr, condition = "message", times = 1) handle_messages(expr, times = 1) handle_warnings(expr, times = 1)
expr |
an expression |
condition |
(character) one of "message" or "warning" |
times |
(integer) max. times a condition should be thrown. default: 1 |
Uses ConditionKeeper internally
whatever the expr
returns
foo <- function(x) { message("you gave: ", x) return(x) } foo('a') capture_message(foo('a')) handle_conditions(foo('a')) suppressMessages(handle_conditions(foo('a'))) handle_conditions(foo('a'), "message") bar <- function(x) { for (i in x) message("you gave: ", i) return(x) } bar(1:5) handle_conditions(bar(1:5)) handle_messages(foo('a')) hello <- function(x) { warning("you gave: ", x) return(x) } handle_warnings(hello('a')) # code block handle_warnings({ as.numeric(letters[1:3]) as.numeric(letters[4:6]) as.numeric(letters[7:9]) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.