partial {rmdpartials}R Documentation

Knit a child document and output as is (render markup)

Description

This modifies and extends the knitr::knit_child() function. Defaults change as follows:

Usage

partial(
  input = NULL,
  ...,
  text = NULL,
  output = NULL,
  quiet = TRUE,
  options = NULL,
  envir = parent.frame(),
  name = NULL,
  show_code = FALSE,
  use_strings = TRUE,
  render_preview = needs_preview(),
  preview_output_format = NULL
)

Arguments

input

if you specify a file path here, it will be read in before being passed to knitr (to avoid a working directory mess)

...

ignored, but you can use it to clarify which variables will be used in the rmd partial

text

passed to knitr::knit_child()

output

if you specify a file path here, where to put the file

quiet

passed to knitr::knit_child()

options

defaults to NULL.

envir

passed to knitr::knit_child()

name

a name to use for cacheing and figure paths. Randomly generated if left unspecified.

show_code

whether to print the R code for the partial or just the results (sets the chunk option echo = FALSE while the chunk is being rendered)

use_strings

whether to read in the child file as a character string (solves working directory problems but harder to debug)

render_preview

true if interactive mode is auto-detected, false when actually knitting the partial as a child

preview_output_format

defaults to rmarkdown::html_document() with self_contained set to true

Details

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 to respect conventional scoping rules 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:

Value

Returns rendered markdown with the class "knit_asis". When used interactively, the knit_meta attributes will additionally contain the path of a rendered preview in a temporary directory.

Examples

# super simple partial example
partial(text = "Test")

# an example of a wrapper function that calls partial with an argument
# ensures distinct paths for cache and figures, so that these calls can be looped in parallel
regression_diagnostics <- function(regression, ...) {
   partial(system.file("_regression_diagnostics.Rmd",
           package = "rmdpartials", mustWork = TRUE),
           regression = regression, ...)
}

[Package rmdpartials version 0.5.8 Index]