ABSTRACT

We can cross reference both code chunks and child documents in knitr. This enables us to better organize our source documents. With chunk references, we can easily reuse code chunks without typing them again. We can embed a defined chunk into another chunk, or just reuse a whole chunk as a new chunk. By default, read_chunk() assumes that the R script is labeled, and there is an alternative approach to specify code chunks via the three arguments labels, from, and to, which are vectors of the same length. The chunk option child provides a reference to child documents. Like chunk references, child documents have no limits on the levels of nesting. One child document can have further children documents, and one chunk can include more than one child document. With chunk references and child documents, we can modularize an analysis in the same manner of programming.