RMarkdown combines the core syntax of Markdown with embedded R code chunks to create dynamic documents. It enables easy creation of dynamic documents, reports and presentations which are fully reproducible.
With RMarkdown, we can combine R codes, plots and text to create beautiful reports and presentations. The reports can be generated in different formats such as:
The best part about RMarkdown is when you have to make some changes to your code or the underlying data and recreate the entire document. You can make the necessary changes and RMarkdown will recreate the document with just a single click of a button.
Install and load the rmarkdown package.
# install
library(rmarkdown)
In order to generate PDF documents/presentations, you will need LaTex. If you have not heard of or installed LaTex, you can instead use TinyTex.
install.packages("tinytex")
tinytex::install_tinytex()
It is when creating reports that contain R code, plots and other outputs that we will appreciate RMarkdown the most. It saves us from the cut/copy/paste ritual while saving time and minimising errors.
Whenever the code or data changes, RMarkdown will automatically regenerate the whole document with the updated results and therein lies its magic.