Introduction
An .Rmd file is an R Markdown
document: Markdown text with chunks of R code in it.
Rendering the document runs the code and puts its results, such as tables and charts,
into the output, which can be a web page, a PDF, a Word document or a slide show. It is
widely used for reports and teaching in statistics and data analysis.
Unlike a Jupyter notebook, the file holds only the source; the results are made again each time it is rendered.
Structure
An R Markdown file is plain text. It usually starts with a YAML header between two
lines of ---, giving the title, author and output format. The body is
Markdown. Code chunks are fenced with three backticks, with the language and options in
braces on the opening line, such as {r summary, echo=FALSE}. Short pieces
of code can also run inline, written as `r expression`.
Rendering is done by the rmarkdown R package: knitr runs the chunks and
writes a plain Markdown file with the results, and Pandoc turns that into the final
format.
---
title: "Fuel economy"
output: html_document
---
Cars in the `mtcars` data set average `r round(mean(mtcars$mpg), 1)` miles per gallon.
```{r plot, echo=FALSE}
plot(mtcars$wt, mtcars$mpg)
```
Links
Software
- RStudio (Windows, macOS, Linux)
- rmarkdown, the R package that renders it (Windows, macOS, Linux)
- Quarto, which can also render
.Rmdfiles (Windows, macOS, Linux) - Pandoc, which makes the final document (Windows, macOS, Linux)
- Visual Studio Code, with an R extension (Windows, macOS, Linux)
Developers
- knitr, R package that runs the code chunks
Reference
- R Markdown: The Definitive Guide, by the package’s authors