+ - 0:00:00
Notes for current slide
Notes for next slide

08

Parameters

1 / 12

Parameters in RStudio

1

2 / 12

Knit with Parameters

Screenshot of the knit dropdown menu

Screenshot of the YAML code that then appears in the wizard to select parameters

3 / 12

This uses {shiny} and may be prompted to install for use

Inline Parameters

Report relates to Series `r params$series`

4 / 12

Inline Parameters

Report relates to Series `r params$series`

Screenshot of the rendered html where code is now shown as text "Series 1"

4 / 12

R code Parameters

5 / 12

R code Parameters

series_ratings <- ratings %>%
filter(series == params$series)
6 / 12

R code Parameters

series_ratings <- ratings %>%
filter(series == params$series)
ratings %>%
filter(series == params$series) %>%
head(5)
#> # A tibble: 5 x 11
#> series episode uk_airdate viewers_7day viewers_28day network_rank channels_rank bbc_iplayer_requests episode_count
#> <dbl> <dbl> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 2010-08-17 2.24 7 NA NA NA 1
#> 2 1 2 2010-08-24 3 3 NA NA NA 2
#> 3 1 3 2010-08-31 3 2 NA NA NA 3
#> 4 1 4 2010-09-07 2.6 4 NA NA NA 4
#> 5 1 5 2010-09-14 3.03 1 NA NA NA 5
#> # ... with 2 more variables: us_season <dbl>, us_airdate <chr>
6 / 12

In chunk settings

---
params:
show_code: FALSE
---
7 / 12

In chunk settings

---
params:
show_code: FALSE
---

Also add this to the global options:

knitr::opts_chunk$set(echo = params$show_code)

7 / 12

Shiny Controls

2

8 / 12

Shiny Controls

title: "The Great British Bake Off"
output: html_document
params:
series:
label: "Series numbers"
value: 1
input: slider
min: 1
max: 9
step: 1
  • label: text
  • value: starting point
  • input: type of wizard
  • min: minimum that you set
  • max: maximum that you set
  • step: increments (default gives smaller points that don't match data)
9 / 12

The params: YAML code uses {shiny} which needs to be installed.

When searching for options related to types of input consider adding shiny to the search.

Your turn

🧶 Knit button and Knit with Parameters... after each step

  1. Install and add library() call for either wesanderson

  2. Add a new parameter called palette: spaced like series:

  3. Add under the parameter:

label: "Give this a new name?"
value: Darjeeling1
input: select
choices: [GrandBudapest1, Darjeeling1, Darjeeling2, FantasticFox1, Royal2]
  1. Add code to the ggplot2 to change the output colours: + scale_colour_manual(values = wes_palette(params$palette))

psst...01-bakeoff-report-alison.Rmd has all the code...

psst-psst...answer on the next slide...

05:00
10 / 12

Issues may occur with grey pop up from shiny for some computers - possibly VPN/network issues.

Answer

palette:
label: "Wes Anderson palette:"
value: GrandBudapest1
input: select
choices: [GrandBudapest1, Darjeeling1, Darjeeling2, FantasticFox1, Royal2]
11 / 12

Next section...

12 / 12

Parameters in RStudio

1

2 / 12
Paused

Help

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