asis_output {knitr} | R Documentation |
This is a convenience function that assigns the input object a class named
knit_asis
, so that knitr will treat it as is (the effect is the
same as the chunk option results = 'asis'
) when it is written to the
output.
asis_output(x, meta = NULL, cacheable = length(meta) == 0)
x |
an R object (typically a character string, or can be converted to a
character string via |
meta |
additional metadata of the object to be printed (the metadata
will be collected when the object is printed, and accessible via
|
cacheable |
a logical value indicating if this object is cacheable |
This function is normally used in a custom S3 method based on the printing
function knit_print()
.
For the cacheable
argument, you need to be careful when printing the
object involves non-trivial side effects, in which case it is strongly
recommended to use cacheable = FALSE
to instruct knitr that this
object should not be cached using the chunk option cache = TRUE
,
otherwise the side effects will be lost the next time the chunk is knitted.
For example, printing a shiny input element in an R Markdown document
may involve registering metadata about some JavaScript libraries or
stylesheets, and the metadata may be lost if we cache the code chunk, because
the code evaluation will be skipped the next time.
This function only works in top-level R expressions, and it will not work when it is called inside another expression, such as a for-loop. See https://github.com/yihui/knitr/issues/1137 for a discussion.
# see ?knit_print