| execute_example | R Documentation |
This function executes the example code and captures the output and messages. If the example code issues an unexpected message, an error is issued.
execute_example(code, expected_cnds = NULL, env = caller_env())
code |
The example code The code is expected to be a character vector of R code lines.
|
expected_cnds |
Expected conditions
|
env |
The environment in which to evaluate the example code
|
A character vector of the input code and the output and messages
created by the code. Output and messages are prefixed by "#>".
admiraldev:::execute_example("1 + 1")
#> [1] "1 + 1\n#> [1] 2"
admiraldev:::execute_example("log(-1)")
#> Error in capture_output(!!expr$expr, srcref = srcref, expected_cnds = expected_cnds, :
#> 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`.
admiraldev:::execute_example("log(-1)", expected_cnds = "warning")
#> [1] "log(-1)\n#> [1] NaN\n#> Warning in log(-1) : NaNs produced"Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.