Skip to content

Commit

Permalink
export engine_output() for @casallas per discussion in #866
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 23, 2014
1 parent 2ed05f9 commit bd2dc6b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -23,6 +23,7 @@ export(current_input)
export(dep_auto)
export(dep_prev)
export(eclipse_theme)
export(engine_output)
export(fig_path)
export(hook_ffmpeg_html)
export(hook_movecode)
Expand Down
17 changes: 15 additions & 2 deletions R/engine.R
Expand Up @@ -31,8 +31,21 @@
#' names(knit_engines$get())
knit_engines = new_defaults()

# give me source code, text output and I return formatted text using the three
# hooks: source, output and chunk
#' An output wrapper for language engine output
#'
#' 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.
#' @param options a list of chunk options (usually this is just the object
#' \code{options} passed to the engine function; see
#' \code{\link{knit_engines}})
#' @param code the source code of the chunk, to which the output hook
#' \code{source} is applied, unless the chunk option \code{echo == FALSE}
#' @param out the text output from the engine, to which the hook \code{output}
#' is applied, unless the chunk option \code{results == 'hide'}
#' @param extra any additional text output that you want to include
#' @return A character string generated from the source code and output using
#' the appropriate output hooks.
#' @export
engine_output = function(options, code, out, extra = NULL) {
if (length(code) != 1L) code = paste(code, collapse = '\n')
if (length(out) != 1L) out = paste(out, collapse = '\n')
Expand Down
27 changes: 27 additions & 0 deletions man/engine_output.Rd
@@ -0,0 +1,27 @@
\name{engine_output}
\alias{engine_output}
\title{An output wrapper for language engine output}
\usage{
engine_output(options, code, out, extra = NULL)
}
\arguments{
\item{options}{a list of chunk options (usually this is just the object
\code{options} passed to the engine function; see
\code{\link{knit_engines}})}

\item{code}{the source code of the chunk, to which the output hook
\code{source} is applied, unless the chunk option \code{echo == FALSE}}

\item{out}{the text output from the engine, to which the hook \code{output}
is applied, unless the chunk option \code{results == 'hide'}}

\item{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.
}
\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.
}

0 comments on commit bd2dc6b

Please sign in to comment.