capture_output | R Documentation |
The function captures both output and expected messages from an R expression. If the expression results in an unexpected message, an error is issued.
capture_output(expr, srcref = NULL, expected_cnds = NULL, env = caller_env())
expr |
An R expression to evaluate
|
srcref |
The source reference of the expression
|
expected_cnds |
A character vector of expected conditions If the expression issues a condition of a class that is in this vector, the condition is ignored but added to the return value. Otherwise, an error is issued.
|
env |
The environment in which to evaluate the expression
|
A character vector of captured output and messages
capture_output(1 + 1) #> [1] "[1] 2" capture_output(log(-1)) #> Error in capture_output(log(-1)) : The expression #> > log(-1) #> issued an unexpected condition: #> NaNs produced #> If this is expected, add any of the classes "simpleWarning", "warning", and #> "condition" to the argument `expected_cnds`. capture_output(log(-1), expected_cnds = "warning") #> [1] "[1] NaN" "Warning in log(-1) : NaNs produced"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.