knitr is a really important tool for reproducible research. You create documents that are a mixture of text and code; when processed through knitr, the code is replaced by the results and/or figures produced.

Note: people are moving from R Markdown to Quarto, so maybe stop reading this and go look at Quarto.

Yihui Xie, the developer of knitr, has written clear and thorough documentation, many useful examples and demos, and a very nice book. Nevertheless, I thought it might be useful to have some of the basic things explained again a bit differently.

And so, here is a brief guide to knitr, covering the fundamentals of its use with Markdown, AsciiDoc, and LaTeX.

If you find knitr useful, consider buying R Markdown: The Definitive Guide by Yihui Xie, JJ Allaire, and Garrett Grolemund.

The source for this tutorial is here. If you have suggestions or corrections, please submit an issue.

Also see my tutorials on git/github, GNU make, R packages, making a web site with GitHub Pages, data organization, and reproducible research.