Most software users must have heard of the DRY principle (i.e., “Don’t Repeat Yourself”). If you repeat a piece of code or text for multiple times in a document, it will be a pain to maintain these copies. Ideally, you only maintain a single copy, and reuse it programmatically in other places.
For knitr documents, you can freely reuse code chunks. We have introduced three methods in the R Markdown Cookbook (Section 14.1). These methods teach you how to reuse the code of …