| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/output.R |
| 3 |
\name{asis_output} |
| 4 |
\alias{asis_output} |
| 5 |
\title{Mark an R object with a special class} |
| 6 |
\usage{ |
| 7 |
asis_output(x, meta = NULL, cacheable = NA) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{An R object. Typically a character string, or an object which can |
| 11 |
be converted to a character string via \code{\link{as.character}()}.} |
| 12 |
|
| 13 |
\item{meta}{Additional metadata of the object to be printed. The metadata |
| 14 |
will be collected when the object is printed, and accessible via |
| 15 |
\code{knit_meta()}.} |
| 16 |
|
| 17 |
\item{cacheable}{Boolean indicating whether this object is cacheable. If |
| 18 |
\code{FALSE}, \pkg{knitr} will stop when caching is enabled on code chunks |
| 19 |
that contain \code{asis_output()}.} |
| 20 |
} |
| 21 |
\description{ |
| 22 |
This is a convenience function that assigns the input object a class named |
| 23 |
\code{knit_asis}, so that \pkg{knitr} will treat it as is (the effect is the |
| 24 |
same as the chunk option \code{results = 'asis'}) when it is written to the |
| 25 |
output. |
| 26 |
} |
| 27 |
\details{ |
| 28 |
This function is normally used in a custom S3 method based on the printing |
| 29 |
function \code{\link{knit_print}()}. |
| 30 |
|
| 31 |
For the \code{cacheable} argument, you need to be careful when printing the |
| 32 |
object involves non-trivial side effects, in which case it is strongly |
| 33 |
recommended to use \code{cacheable = FALSE} to instruct \pkg{knitr} that this |
| 34 |
object should not be cached using the chunk option \code{cache = TRUE}, |
| 35 |
otherwise the side effects will be lost the next time the chunk is knitted. |
| 36 |
For example, printing a \pkg{shiny} input element or an HTML widget in an R |
| 37 |
Markdown document may involve registering metadata about some JavaScript |
| 38 |
libraries or stylesheets, and the metadata may be lost if we cache the code |
| 39 |
chunk, because the code evaluation will be skipped the next time. This |
| 40 |
particular issue has been solved in \pkg{knitr} after v1.13 (the metadata |
| 41 |
will be saved and loaded automatically when caching is enabled), but not all |
| 42 |
metadata can be saved and loaded next time and still works in the new R |
| 43 |
session. |
| 44 |
} |
| 45 |
\note{ |
| 46 |
This function only works in top-level R expressions, and it will not |
| 47 |
work when it is called inside another expression, such as a for-loop. See |
| 48 |
\url{https://github.com/yihui/knitr/issues/1137} for a discussion. |
| 49 |
} |
| 50 |
\examples{ |
| 51 |
# see ?knit_print |
| 52 |
} |