01
Wifi network name
Functions
Wifi password
Stata_16
Time | Activity |
---|---|
09:00 - 10:30 | Session 1 (R Markdown Basics) |
10:30 - 11:00 | Break ☕ |
11:00 - 12:30 | Session 2 (Advanced R Markdown) |
12:30 - 01:30 | Lunch 🍱 |
01:30 - 03:00 | Session 3 (Templates) |
03:00 - 03:30 | Break 🍵 |
03:30 - 05:00 | Session 4 (Collections) |
All content is CC-BY. All art (unless otherwise noted) is by Desirée De Leon, CC-BY-NC-ND.
?
An authoring framework for data science.
A document format (.Rmd
).
An R package named rmarkdown
.
A file format for making dynamic documents with R.
A tool for integrating prose, code, and results.
A computational document.
Wizardry.
?
html_document
https://github.com/ysc2019-workshop/01-basics
Click on "Use this template" (make sure you are logged in)
Click on green button, then the clipboard to copy HTTPS
Join space > Click on "Projects" (nothing there)
New Project from GitHub Repo
Use your HTTPS link:
I promise! Still in rstudio.cloud:
library(usethis)use_git_config( scope = "project", user.name = "Jane", user.email = "jane@example.org")
Find a partner and look at 01-bakeoff-report.Rmd
together.
Look at the source, then 🧶 Knit to HTML.
Try to identify these parts in the source and the output:
The metadata
The text
The code
The output
If this was easy, try to find all code that produces a plot.
05:00
We look at the source anatomy for 01-bakeoff-report.Rmd
together:
The metadata
The text
The code
We look at the output anatomy for 01-bakeoff-report.Rmd
together:
The metadata
The text
The code
The output
Art by Allison Horst
1
1
"YAML Ain't Markup Language"
---key: value---
---title: The Great British Bake Offoutput: html_document---
---title: The Great British Bake Offoutput: html_document: toc: true---
Use ?html_document
from your R console to:
Add a floating table of contents
Add a theme
🧶 Knit to HTML to see the output.
If this was easy, try to embed the Rmd
source code to download.
psst...answers on the next slide...
03:00
---title: The Great British Bake Offoutput: html_document: toc: true toc_float: true theme: flatly code_download: true---
---title: The Great British Bake Offoutput: html_document: toc: true toc_float: true theme: flatly code_download: trueparams: series: '1'---
Change this:
---title: The Great British Bake Offoutput: html_document: toc: true toc_float: true theme: flatly code_download: trueparams: series: '1'---
To this:
---title: The Great British Bake Offoutput: html_document: toc: true toc_float: true theme: flatly code_download: trueparams: series: '2'---
Now click on knit button and pick "Knit with Parameters." How is this different from what you did above?
03:00
2
2
# HEADER 1## HEADER 2### HEADER 3#### HEADER 4##### HEADER 5###### HEADER 6
# HEADER 1## HEADER 2### HEADER 3#### HEADER 4##### HEADER 5###### HEADER 6
**The Great British Bake Off** (often abbreviated to _Bake Off_ or _GBBO_) is a British television baking competition.
**The Great British Bake Off** (often abbreviated to _Bake Off_ or _GBBO_) is a British television baking competition.
The Great British Bake Off (often abbreviated to Bake Off or GBBO) is a British television baking competition.
The original cast included:- Sue Perkins (_host_)- Mel Giedroyc (_host_)- Mary Berry (_judge_) and- Paul Hollywood (_judge_).In each episode, the amateur bakers are given **three challenges** based on that week's theme.1. a signature bake,1. a technical challenge,1. a show-stopper.
The original cast included:- Sue Perkins (_host_)- Mel Giedroyc (_host_)- Mary Berry (_judge_) and- Paul Hollywood (_judge_).In each episode, the amateur bakers are given **three challenges** based on that week's theme.1. a signature bake,1. a technical challenge,1. a show-stopper.
The original cast included:
In each episode, the amateur bakers are given three challenges based on that week's theme.
Competitive baking, such as making Victoria sponge (_pictured_), is part of the classic English village fête,which inspired the series.
Competitive baking, such as making Victoria sponge (_pictured_), is part of the classic English village fête,which inspired the series.
Competitive baking, such as making Victoria
sponge (pictured), is part of the classic
English village fête,
which inspired the series.
Competitive baking, such as making Victoria sponge (_pictured_), is part of the classic English village fête,which inspired the series.[Photo](https://en.wikipedia.org/)
Competitive baking, such as making Victoria sponge (_pictured_), is part of the classic English village fête,which inspired the series.[Photo](https://en.wikipedia.org/)
Competitive baking, such as making Victoria sponge (pictured), is part of the classic English village fête, which inspired the series.
How do you add headers in Markdown?
! Header
- Header
# Header
1. Header
How do you add headers in Markdown?
! Header
- Header
# Header
1. Header
What about lists? Bulleted? Numbered?
! Item 1
- Item 1
# Item 1
1. Item 1
3
3
```{r}ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)```
What is the fate of this chunk?
```{r}ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)```
What is the fate of this chunk?
ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)#> # A tibble: 1 x 8#> series episode uk_airdate viewers_7day viewers_28day network_rank#> <int> <int> <date> <dbl> <dbl> <int>#> 1 1 5 2010-09-14 3.03 1 NA#> # … with 2 more variables: channels_rank <int>, bbc_iplayer_requests <dbl>
```{r}top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)```
What fate do you predict here?
```{r}top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)```
What fate do you predict here?
top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)
```{r}top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)top_viewers```
```{r}top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)top_viewers```
top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day)top_viewers#> # A tibble: 1 x 8#> series episode uk_airdate viewers_7day viewers_28day network_rank#> <int> <int> <date> <dbl> <dbl> <int>#> 1 1 5 2010-09-14 3.03 1 NA#> # … with 2 more variables: channels_rank <int>, bbc_iplayer_requests <dbl>
```{r}ggplot(viewers, aes(episode, viewers, colour = days, group = days)) + geom_point() + geom_line() + labs(x = "Episode", y = "Viewers (millions)") + expand_limits(y = 0) ```
What about this one?
```{r}ggplot(viewers, aes(episode, viewers, colour = days, group = days)) + geom_point() + geom_line() + labs(x = "Episode", y = "Viewers (millions)") + expand_limits(y = 0) ```
What about this one?
ggplot(viewers, aes(episode, viewers, colour = days, group = days)) + geom_point() + geom_line() + labs(x = "Episode", y = "Viewers (millions)") + expand_limits(y = 0)
Together we:
Add chunks with button or:
Command (or Cmd) ⌘
+ Option (or Alt) ⌥
+ i
(Mac)
Ctrl + Alt + i
(Windows/Linux)
Run chunks by:
Run current chunk button (interactive)
Knit button / run all chunks
The top viewed episode in series 1 was episode
`r top_viewers %>% pull(episode)`
The top viewed episode in series 1 was episode
`r top_viewers %>% pull(episode)`
The top viewed episode in series 1 was episode 5
4
4
```{r}glimpse(ratings)```
glimpse(ratings)#> Observations: 84#> Variables: 8#> $ series <int> 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3…#> $ episode <int> 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 1…#> $ uk_airdate <date> 2010-08-17, 2010-08-24, 2010-08-31, 2010-0…#> $ viewers_7day <dbl> 2.24, 3.00, 3.00, 2.60, 3.03, 2.75, 3.10, 3…#> $ viewers_28day <dbl> 7, 3, 2, 4, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1…#> $ network_rank <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…#> $ channels_rank <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…#> $ bbc_iplayer_requests <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
```{r echo=FALSE}glimpse(ratings)```
#> Observations: 84#> Variables: 8#> $ series <int> 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3…#> $ episode <int> 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 1…#> $ uk_airdate <date> 2010-08-17, 2010-08-24, 2010-08-31, 2010-0…#> $ viewers_7day <dbl> 2.24, 3.00, 3.00, 2.60, 3.03, 2.75, 3.10, 3…#> $ viewers_28day <dbl> 7, 3, 2, 4, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1…#> $ network_rank <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…#> $ channels_rank <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…#> $ bbc_iplayer_requests <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
```{r eval=FALSE}glimpse(ratings)```
glimpse(ratings)
```{r include=FALSE}glimpse(ratings)```
```{r echo=TRUE, results='hide'}glimpse(ratings)```
glimpse(ratings)
```{r message=FALSE, warning=FALSE}library(tidyverse)```
library(tidyverse)
str(knitr::opts_chunk$get())#> List of 53#> $ eval : logi TRUE#> $ echo : logi TRUE#> $ results : chr "markup"#> $ tidy : logi FALSE#> $ tidy.opts : NULL#> $ collapse : logi TRUE#> $ prompt : logi FALSE#> $ comment : chr "#>"#> $ highlight : logi TRUE#> $ strip.white : logi TRUE#> $ size : chr "normalsize"#> $ background : chr "#F7F7F7"#> $ cache : logi FALSE#> $ cache.path : chr "01-basics_cache/html/"#> $ cache.vars : NULL#> $ cache.lazy : logi TRUE#> $ dependson : NULL#> $ autodep : logi FALSE#> $ cache.rebuild: logi FALSE#> $ fig.keep : chr "high"#> $ fig.show : chr "asis"#> $ fig.align : chr "default"#> $ fig.path : chr "01-basics_files/figure-html/"#> $ dev : chr "png"#> $ dev.args : NULL#> $ dpi : num 72#> $ fig.ext : NULL#> $ fig.width : num 7#> $ fig.height : num 7#> $ fig.env : chr "figure"#> $ fig.cap : NULL#> $ fig.scap : NULL#> $ fig.lp : chr "fig:"#> $ fig.subcap : NULL#> $ fig.pos : chr ""#> $ out.width : NULL#> $ out.height : NULL#> $ out.extra : NULL#> $ fig.retina : num 1#> $ external : logi TRUE#> $ sanitize : logi FALSE#> $ interval : num 1#> $ aniopts : chr "controls,loop"#> $ warning : logi TRUE#> $ error : logi FALSE#> $ message : logi TRUE#> $ render : NULL#> $ ref.label : NULL#> $ child : NULL#> $ engine : chr "R"#> $ split : logi FALSE#> $ include : logi TRUE#> $ purl : logi TRUE
Place between curly braces{r option=value}
Multiple options separated by commas{r option1=value, option2=value}
Careful! The r
part is the code engine (other engines possible)
```{r peek, echo=FALSE, results='hide'}glimpse(ratings)```
Place between curly braces{r label}
Separated options with commas{r label, option1=value}
Careful! No duplicate chunk labels
```{r peek}head(ratings)```
Error in parse_block(g[-1], g[1], params.src) : duplicate label 'peek'Calls: <Anonymous> ... process_file -> split_file -> lapply -> FUN -> parse_blockExecution halted
how can we make it easier on ourselves to explore the code in here?
show how to add chunk labels and view in IDE interactively
https://masalmon.eu/2017/08/08/chunkpets/; https://www.express.co.uk/news/nature/770211/pet-sheep-lamb-rasied-dog-farm-nature
my-plot
myplot
myplot1
myplot-1
MY-PLOT
my_plot
my plot
everything else!
```{r setup, include=FALSE}knitr::opts_chunk$set( collapse = TRUE, comment = "#>", out.width = "100%" )```
A special chunk label: setup
Typically #1
All following chunks will use these options (i.e., sets global chunk options)
Tip: set include=FALSE
You can (and should) use individual chunk options too
We do this together:
Add fig.path = "figs/"
as a knitr code chunk option for a single plot (watch what happens if we don't include the backslash!)
Knit and behold
We add it to a global setup chunk.
Customize this report.
Label the code chunk with your plot in it.
Add your setup chunk.
Use the RStudio outline pane; rejoice!
Build a graphical user interface for parameters.
If this was easy, try adding a parameter for color palette and add in a package like wesanderson — use the parameter in our ggplot2 code.
psst...01-bakeoff-report-alison.Rmd
is there...
psst-psst...answers on the next slide...
05:00
params: series: label: "Series:" value: 1 input: numeric min: 1 max: 9 step: 1 palette: label: "Wes Anderson palette:" value: GrandBudapest1 input: select choices: [GrandBudapest1, Darjeeling1, Darjeeling2, FantasticFox1, Royal2]
We live demo changing the main "landing page" name to index.Rmd
, knit, then deploy again: https://app.netlify.com/drop
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Organize your text: use markdown headers with #
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Organize your text: use markdown headers with #
✔️ Organize your code: use knitr
chunk labels
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Organize your text: use markdown headers with #
✔️ Organize your code: use knitr
chunk labels
✔️ Style your text: use markdown bold, italics, bullets, and lists
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Organize your text: use markdown headers with #
✔️ Organize your code: use knitr
chunk labels
✔️ Style your text: use markdown bold, italics, bullets, and lists
✔️ Style your output: use knitr
chunk options
✔️ Document your document: use YAML to set up meaningful metadata
✔️ Style your document: use YAML to add options to your chosen output format
✔️ Organize your text: use markdown headers with #
✔️ Organize your code: use knitr
chunk labels
✔️ Style your text: use markdown bold, italics, bullets, and lists
✔️ Style your output: use knitr
chunk options
🧶 early, 🧶 often
30:00
Wifi network name
Functions
Wifi password
Stata_16
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |