|Original author(s)||Yihui Xie|
|Initial release||17 January 2012|
1.23 / 18 May 2019
knitr is an engine for dynamic report generation with R. It is a package in the statistical programming language R that enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and reStructuredText documents. The purpose of knitr is to allow reproducible research in R through the means of Literate Programming. It is licensed under the GNU General Public License.
knitr was inspired by Sweave and written with a different design for better modularization, so it is easier to maintain and extend. Sweave can be regarded as a subset of knitr in the sense that all features of Sweave are also available in knitr. Some of knitr's extensions include the R Markdown format (used in reports published on RPubs), caching, TikZ graphics and support to other languages such as Python, Perl, C++, Shell scripts and CoffeeScript, and so on.
Workflow of KnitR
KnitR consists of standard e.g. MarkDown document with R-code chunks integrated in the document. The code chunks can be regarded as R-scripts that
- load data,
- performs data processing and
- creates output data (e.g. descriptive analysis) or output graphics (e.g. boxplot diagram).
The implementation of logical conditions in R can provide text elements for the dynamic report depended on the statistical analysis. For example:
The Wilcoxon Sign test was applied as statistical comparison of the average of two dependent samples above. In this case, the calculated P-value was 0.56 and hence greater than the significance (0.05 by default). This implies that "H0: there is no difference between the results in data1 and data2" must be accepted.
The text fragments are selected according to the script's results. In this example, if the P-value was lower than the significance, different text fragments would be inserted in the dynamic report. In particular, the second sentence would swap "less" for "greater," and the third sentence would be replaced to reflect rejection of the null hypothesis. Using this workflow allows creating new reports simply by supplying new input data, ensuring the methodology is reproduced identically.
- Xie, Yihui (2015). Dynamic Documents with R and knitr, 2nd Edition. Chapman & Hall/CRC. ISBN 9781498716963.
- Xie, Yihui. "knitr: A General-Purpose Tool for Dynamic Report Generation in R" (PDF).
- RStudio, Inc. "R Markdown — Dynamic Documents for R".
- RStudio, Inc. "Easy web publishing from R".
|This programming-tool-related article is a stub. You can help Wikipedia by expanding it.|