Awesome (free) resource: https://bookdown.org/yihui/rmarkdown/
Jan 28, 2026
Awesome (free) resource: https://bookdown.org/yihui/rmarkdown/
YAML Ain’t Markup Language
.Rmd------ title: My Document author: Me output: html_document ---
Basic metadata
--- title: "My Analysis" subtitle: "A deeper dive" author: "Dr. Gurarie" date: "January 28, 2026" output: html_document ---
Key rules
Documents
output: html_document output: pdf_document output: word_document
Presentations
output: ioslides_presentation output: slidy_presentation output: beamer_presentation
Note: pdf_document and beamer_presentation require LaTeX
output:
html_document:
toc: true
toc_depth: 3
toc_float: true
Options
toc: true — enable TOCtoc_depth: n — heading levelstoc_float: true — sticky sidebar (html only)output:
html_document:
toc: true
toc_float: true
theme: flatly
code_folding: hide
fig_width: 8
fig_height: 6
Each output type has its own set of sub-options — check the documentation!
Dynamic date
date: "`r Sys.Date()`"
outputs:
date: "2026-01-26"
Or Dynamic anything!
author: "`r paste(LETTERS[c(8,25,1,20,20)], collapse = "")`" date: "`r Sys.Date()`"
outputs:
author: "HYATT" date: "2026-01-26"
install.packages("rmdformats")
output: rmdformats::readthedown
output: rmdformats::material
output: rmdformats::downcute
Check out gallery: github.com/juba/rmdformats
install.packages("prettydoc")
output:
prettydoc::html_pretty:
theme: cayman
Themes available:
caymantactilearchitectleonidshpstr| Package | Output | Notes |
|---|---|---|
ioslides |
HTML slides | Built-in, simple |
xaringan |
HTML slides | Highly customizable, remark.js |
revealjs |
HTML slides | 3D transitions |
beamer |
PDF slides | LaTeX-based |
xaringanFor example: Lecture: How to Model Anything
---
title: "How to model just about anything<br>(but especially habitat) Part II"
subtitle: "EFB 390: Wildlife Ecology and Management"
author: "Dr. Elie Gurarie"
date: "October 3, 2024"
output:
xaringan::moon_reader:
css: [default, default-fonts, mycss.css]
nature:
highlightStyle: github
countIncrementalSlides: false
highlightLines: true
titleSlideClass: ["center","middle","white"]
ratio: '16:9'
editor_options:
chunk_output_type: console
---
Input:
```{r}
mean(c(1, 2, 3))
```Output:
mean(c(1, 2, 3))
## [1] 2
```{r my-summary-stats}
summary(iris)
```
Why name chunks?
Rules: no spaces, no underscores (use -)
eval: Run the Code?Input:
```{r eval=FALSE}
2 + 2
```
```{r eval=2}
2 + 2
cat("Dr. Green Teach Good")
```
Output:
2 + 2
(code shown, not executed)
## 2 + 2
cat("Dr. Green Teach Good")
## Dr. Green Teach Good
only line 2 evaluated
echo: Show the Code?Input:
```{r echo=FALSE}
2 + 2
```
```{r echo=-2}
2 + 2
cat("Dr. Green Teach Good")
```Output:
## [1] 4
output only, code hidden
2 + 2
## [1] 4
## Dr. Green Teach Good
don’t show the second line of code - just the output
eval + echo Combinationseval |
echo |
Result |
|---|---|---|
| TRUE | TRUE | Code + Output |
| TRUE | FALSE | Output only |
| FALSE | TRUE | Code only (display) |
| FALSE | FALSE | Nothing! |
Input:
```{r}
k <- 10
x <- seq(-1,1,length = 1000)
M <- sapply(k:1, function(f)
cos(x*f * pi) * sqrt(1 - x^2))
matplot(x, M, type = "l", col = 1:k,
lty = 1, lwd = seq(1,3,length = k))
```Output:
Input:
```{r fig.width=4, fig.height=3}
k <- 10
x <- seq(-1,1,length = 1000)
M <- sapply(k:1, function(f)
cos(x*f * pi) * sqrt(1 - x^2))
matplot(x, M, type = "l", col = 1:k,
lty = 1, lwd = seq(1,3,length = k))
```Output:
out.widthInput:
```{r out.width="50%"}
k <- 10
x <- seq(-1,1,length = 1000)
M <- sapply(k:1, function(f)
cos(x*f * pi) * sqrt(1 - x^2))
matplot(x, M, type = "l", col = 1:k,
lty = 1, lwd = seq(1,3,length = k))
```
out.width scales the displayed size
fig.width sets the rendered size
Output:
cache: Save Time on Long Computations``` r model <- lm(mpg ~ ., data = mtcars) ```
_cache/ folderCaution: Won’t detect changes in upstream dependencies.
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE,
fig.width = 8,
fig.height = 5
)
```
include = FALSE hides it entirely| Option | Purpose |
|---|---|
message = FALSE |
Hide messages |
warning = FALSE |
Hide warnings |
include = FALSE |
Run but hide everything |
results = 'hide' |
Hide text output only |
error = TRUE |
Keep knitting despite errors |
comment = "" |
Remove ## from output |