This is an R Markdown file, a plain text file that has the extension .Rmd
. You can download a copy here.
Notice that the file contains three types of content:
---
s```
sWhen you open the file in the RStudio IDE, it becomes a notebook interface for R. You can run each code chunk by clicking the icon. RStudio executes the code and display the results inline with your file.
To generate a report from the file, run the render
command:
library(rmarkdown)
render("1-example.Rmd")
Better still, use the “Knit” button in the RStudio IDE to render the file and preview the output with a single click or keyboard shortcut (⇧⌘K).
R Markdown generates a new file that contains selected text, code, and results from the .Rmd file. The new file can be a finished web page, PDF, MS Word document, slide show, notebook, handout, book, dashboard, package vignette or other format.
When you run render
, R Markdown feeds the .Rmd file to knitr, which executes all of the code chunks and creates a new markdown (.md) document which includes the code and it’s output.
The markdown file generated by knitr is then processed by pandoc which is responsible for creating the finished format.
This may sound complicated, but R Markdown makes it extremely simple by encapsulating all of the above processing into a single render
function.