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,languageorexpression) code to evaluate. It is possible to preserve original formatting of thecodeby providing acharacteror anexpressionbeing 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)
#> $`80d56d8e`
#> [1] "iris <- iris"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $`5d57a431`
#> [1] "a <- 1"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $d15f1974
#> [1] "b <- 2L # with comment"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $da4de720
#> [1] "library(checkmate)"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> $fb294b6f
#> [1] "assert_number(a)"
#> attr(,"params")
#> list()
#> attr(,"lang")
#> [1] "R"
#> attr(,"class")
#> [1] "code_chunk"
#>
#> attr(,"class")
#> [1] "teal_card"
#> attr(,"metadata")
#> list()