ABSTRACT

The design of the knitr package is flexible enough to process any plain text documents in theory. The three key components of the design are a source parser, a code evaluator, and an output renderer. The parser parses the source document and identifies computer code chunks as well as inline code from the document; the evaluator executes the code and returns results; the renderer formats the results from computing in an appropriate format, which will finally be combined with the original documentation. The code evaluator is independent of the document format, whereas the parser and the renderer have to take the document format into consideration. The former corresponds to the input syntax, and the latter is related to the output syntax. Regular expressions are used to identify code blocks and other elements such as inline code in a document. Customization is possible to define one's own syntax to parse a source document.