knitr (version 0.4)

knit_child: Knit a child document

Description

This function is for LaTeX only except when it is used to extract R code from the document; by default it knits a child document and returns the command to input the result into the main document. It is designed to be used in the inline R code and serves as the alternative to the SweaveInput command in Sweave.

Usage

knit_child(..., eval = TRUE)

Arguments

...
arguments passed to knit
eval
logical: whether to evaluate the child document

Value

  • A character string of the form child-doc.tex or source("child-doc.R"), depending on the argument tangle passed in.

Details

The LaTeX command used to input the child document (usually input or include) is from the package option child.command (opts_knit$get('child.command')).

When we call purl() to extract R code, the code in the child document is extracted and saved into an R script.

The path of the child document is relative to the parent document.

References

http://yihui.name/knitr/demo/child/

Examples

Run this code
## you can write \\Sexpr{knit_child('child-doc.Rnw')} in
#   an Rnw file 'main.Rnw' to input child-doc.tex in
#   main.tex

## comment out the child doc by
#   \\Sexpr{knit_child('child-doc.Rnw', eval = FALSE)}

## use \\include: opts_knit$set(child.command =
#   'include')

Run the code above in your browser using DataCamp Workspace