<commit_before>---
layout: default
title: Child documents
subtitle: Input child files into the main document
category: demo
---

_Warning: The feature described here relies on the development version of **knitr** on GitHub. General users can start using this feature after this warning message is removed._

Like the command `\SweaveInput{}` in Sweave, **knitr** also has the similar functionality, which enables us to insert child documents into a main document. The idea is like the command `\input{}` or `\include{}` in LaTeX to manage a large document in smaller parts. There are two approaches to input child documents in a main document.

## Using chunk option `child`

The chunk option `child` supports the inclusion of child documents. For example, we have a main document named [`knitr-input.Rnw`](https://github.com/yihui/knitr/blob/master/inst/examples/knitr-input.Rnw) here:

{% highlight tex %}
\documentclass{article}
\begin{document}

<<test-main>>=
options(width = 60)
summary(iris)
@

Let's see how to work with child documents in knitr. Below we input
the file \textsf{knitr-input-child.Rnw}:

<<child-demo, child=knitr-input-child.Rnw, eval=TRUE>>=
@

Done!
<commit_msg>rm the warning since 0.2 has been released<commit_after>---
layout: default
title: Child documents
subtitle: Input child files into the main document
category: demo
---

Like the command `\SweaveInput{}` in Sweave, **knitr** also has the similar functionality, which enables us to insert child documents into a main document. The idea is like the command `\input{}` or `\include{}` in LaTeX to manage a large document in smaller parts. There are two approaches to input child documents in a main document.

## Using chunk option `child`

The chunk option `child` supports the inclusion of child documents. For example, we have a main document named [`knitr-input.Rnw`](https://github.com/yihui/knitr/blob/master/inst/examples/knitr-input.Rnw) here:

{% highlight tex %}
\documentclass{article}
\begin{document}

<<test-main>>=
options(width = 60)
summary(iris)
@

Let's see how to work with child documents in knitr. Below we input
the file \textsf{knitr-input-child.Rnw}:

<<child-demo, child=knitr-input-child.Rnw, eval=TRUE>>=
@

Done!

{'fraction_non_alphanumeric': 0.10502692998204669, 'fraction_numerical': 0.0026929982046678637, 'mean_word_length': 4.70076726342711, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480426', 'n_tokens_mistral': 669, 'n_tokens_neox': 650, 'n_words': 278}