Description Usage Arguments Details Examples
View source: R/rmarkdown_options.R
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
1 | asis_knit_child(..., quiet = TRUE, options = NULL, envir = parent.frame())
|
... |
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()
1 2 3 4 5 6 7 8 9 10 11 12 | ## 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.