View source: R/rmarkdown_options.R
asis_knit_child | R Documentation |
This slightly modifies the knitr::knit_child()
function to have different defaults.
the environment defaults to the calling environment.
the output receives the class knit_asis, so that the output will be rendered "as is" by knitr when calling inside a chunk (no need to set results='asis' as a chunk option).
defaults to quiet = TRUE
asis_knit_child(
input = NULL,
text = NULL,
...,
quiet = TRUE,
options = NULL,
envir = parent.frame()
)
input |
if you specify a file path here, it will be read in before being passed to knitr (to avoid a working directory mess) |
text |
passed to |
... |
passed to |
quiet |
passed to |
options |
defaults to NULL. |
envir |
passed to |
Why default to the calling environment? Typically this function defaults to the global environment. This makes sense if you want to use knit_children in the same context as the rest of the document. However, you may also want to use knit_children inside functions to e.g. summarise a regression using a set of commands (e.g. plot some diagnostic graphs and a summary for a regression nicely formatted).
Some caveats:
the function has to return to the top-level. There's no way to cat()
this from loops or an if-condition without without setting results='asis'. You can however concatenate these objects with paste.knit_asis()
## Not run:
# an example of a wrapper function that calls asis_knit_child with an argument
# ensures distinct paths for cache and figures, so that these calls can be looped in parallel
regression_summary = function(model) {
child_hash = digest::digest(model)
options = list(
fig.path = paste0(knitr::opts_chunk$get("fig.path"), child_hash, "-"),
cache.path = paste0(knitr::opts_chunk$get("cache.path"), child_hash, "-"))
asis_knit_child("_regression_summary.Rmd", options = options)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.