Natya Hans Academic Research Consulting and Services, University of Florida (updated: 2023-11-14)
rmarkdown is the file-format and main interface with R (*.Rmd)knitr runs code and formats results into markdownpandoc converts markdown documents into other formatspandoc.rmarkdown package includes knitr as a dependency. For PDF output, you also need LaTeX. The tinytex package provides a mechanism for a lightweight LaTeX install:
tinytex::install_tinytex()New R Markdown file option in RStudio, or create a plaintext file.
rmarkdown::render("document.Rmd")Knit button in RStudio. 
knitr runs the code chunks and merges the output back into a markdown file.pandoc converts the markdown into the final output format(s). 
About Markdown Markdown is a markup language.
Markdown Formatting Markdown has an intentionally limited set of formatting commands:
Syntax: Headings ```
heading 1 ## heading 2 ### heading 3 ``` renders into
heading 1 ## heading 2 ### heading 3
Syntax: bullets
- bullet list
* sub-item
1. numbered list
2. numbered list
renders into
Syntax: text
**bold**, __bold__
*italic*, _italic_
> This is a quote.
renders into bold, bold italic, italic > This is a quote
Links
Raw URLs:
https://cran.r-project.org/
Formatted links:
[CRAN](https://cran.r-project.org/)
renders into Raw URLs: https://cran.r-project.org/ Formatted links: CRAN
What does R Markdown add? R Markdown adds additional syntax for authoring code-based reports.
Header Information R Markdown files begin with a header:
A More Complex Header
Code Chunks Unexecuted code can be marked with triple backticks
(the backtick is not the same as a single-quote!)
```
print("Hello World!")
```
renders into
print("Hello World!")
Inserting Code Including {r} will execute the code in R and display the result:
```{r}
1 + 1
```
renders into
1 + 1## [1] 2
Code Chunk Options The evaluation of code chunks can be controlled through options, e.g.:
```{r, eval = FALSE}
1 + 1
```
renders into
1 + 1See the description of chunk options for details.
Inline code Code expressions can be embedded inline with text, too.
The square root of 10 is `r sqrt(10)`.
Today's date is `r Sys.Date()`.
renders into The square root of 10 is 3.1622777. Today’s date is 2023-11-14.
Other Coding Languages knitr supports other programming languages. See Section 2.7 of the R Markdown book for details.
Tables (markdown)
| Tables | Are | Cool |
|:-------------|:-------------:|------:|
| col 1 is | left-aligned | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right aligned | $1 |
renders into | Tables | Are | Cool | |:——————————|:—————————–:|————:| | col 1 is | left-aligned | $1600 | | col 2 is | centered | $12 | | col 3 is | right aligned | $1 |
Tables (R code)
```{r, results="asis"}
knitr::kable(mtcars[1:4,1:3],
format = "markdown")
```
renders into | | mpg| cyl| disp| |:————–|—-:|—:|—-:| |Mazda RX4 | 21.0| 6| 160| |Mazda RX4 Wag | 21.0| 6| 160| |Datsun 710 | 22.8| 4| 108| |Hornet 4 Drive | 21.4| 6| 258|
Figures (images)

Nyan Cat: animation of a grey cat with a pop-tart body flying through space and leaving a rainbow trail
Figures (code)
plot(mpg ~ disp, data = mtcars,
cex = 2, cex.lab = 2, cex.axis = 2)
References
.bib format. (plain-text bibtex, most reference managers can output a list in this way)[@{bibentry}], where {bibentry} is the unique identifier for the reference in the bibliography.citr add-in also lets you search for the correct {bibentry}
Example .bib file contents of refs.bib file:
@article{Barkai_1988,
Author = {Amos Barkai and Christopher McQuaid},
Journal = {Science},
Number = {4875},
Pages = {62-64},
Title = {Predator-prey role reversal in a marine benthic ecosystem},
Volume = {242},
Year = {1988}}
Example YAML header
title: "An example document"
author: "Natya Hans"
output: html_document
bibliography: refs.bib
csl: methods-in-ecology-and-evolution.cslFind Citation Style Language (CSL) files at
Example citation
Sometimes whelks eat lobsters [@Barkai_1998].
renders into Sometimes whelks eat lobsters (Barkai and McQuaid, 1988). ### References
html_document - a single HTML filepdf_document - a single PDF file (requires a LaTeX installation, see the tinytex package)word_document - a single MS Word filegithub_document - markdown for rendering in GitHub