Evaluate code in qenv
Usage
# S4 method for class 'teal_report'
eval_code(object, code, code_block_opts = list(), ...)
Arguments
- object
(
teal_report
)- code
(
character
,language
orexpression
) code to evaluate. It is possible to preserve original formatting of thecode
by providing acharacter
or anexpression
being a result ofparse(keep.source = TRUE)
.- code_block_opts
(
list
) Additional options for the R code chunk in R Markdown.- ...
(
dots
) additional arguments passed to future methods.
Value
teal_reporter
environment with the code evaluated and the outputs added
to the card or qenv.error
if evaluation fails.
Details
eval_code()
evaluates given code in the qenv
environment and appends it to the code
slot.
Thus, if the qenv
had been instantiated empty, contents of the environment are always a result of the stored code.
Examples
td <- teal.data::teal_data()
td <- teal.code::eval_code(td, "iris <- iris")
tr <- as.teal_report(td)
tr <- teal.code::eval_code(tr, "a <- 1")
tr <- teal.code::eval_code(tr, "b <- 2L # with comment")
tr <- teal.code::eval_code(tr, quote(library(checkmate)))
tr <- teal.code::eval_code(tr, expression(assert_number(a)))
teal_card(tr)
#> $`4756fe4e`
#> [1] "iris <- iris"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $`22cc2dff`
#> [1] "a <- 1"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $`21da45f1`
#> [1] "b <- 2L # with comment"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $`14825248`
#> [1] "library(checkmate)"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $`4a3c03b9`
#> [1] "assert_number(a)"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> attr(,"class")
#> [1] "teal_card"
#> attr(,"metadata")
#> list()