Learn R Programming

knitr (version 1.34)

engine_output: An output wrapper for language engine output

Description

If you have designed a language engine, you may call this function in the end to format and return the text output from your engine.

Usage

engine_output(options, code, out, extra = NULL)

Arguments

options

A list of chunk options. Usually this is just the object options passed to the engine function; see knit_engines.

code

Source code of the chunk, to which the output hook source is applied, unless the chunk option echo is FALSE.

out

Text output from the engine, to which the hook output is applied, unless the chunk option results is 'hide'

extra

Any additional text output that you want to include.

Value

A character string generated from the source code and output using the appropriate output hooks.

Details

For expert users, an advanced usage of this function is engine_output(options, out = LIST) where LIST is a list that has the same structure as the output of evaluate::evaluate(). In this case, the arguments code and extra are ignored, and the list is passed to knitr::sew() to return a character vector of final output.

Examples

Run this code
# NOT RUN {
library(knitr)
engine_output(opts_chunk$merge(list(engine = "Rscript")),
    code = "1 + 1", out = "[1] 2")
engine_output(opts_chunk$merge(list(echo = FALSE, engine = "Rscript")),
    code = "1 + 1", out = "[1] 2")

# expert use only
engine_output(opts_chunk$merge(list(engine = "python")),
    out = list(structure(list(src = "1 + 1"), class = "source"),
        "2"))
# }

Run the code above in your browser using DataLab