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

Combining code with text!!

05

Inline code

1 / 9

Inline code

1

2 / 9

Combining code with text!!

Inline text formatting

A single back tick denotes a function and changes the format

A single back tick with r denotes code to be run in R `r top_viewers %>% pull(episode)`

3 / 9

Inline code can be formatted on screen to be on multiple lines and will still run but the colouring changes:

5

and automatically indent formatting is lost. It's not a good idea to have a lot of code in inline for ease of debugging.

Inline code - in the YAML

2

4 / 9

Your turn

In the file 01-bakeoff-report.Rmd

1 Add the following in the YAML and 🧶 Knit

---
date: '2022-01-01'
---

2 Replace the date with this code

---
date: '`r Sys.Date()`'
---

3 Replace the date with this code

---
date: '`r lubridate::today()`'
---
03:00
5 / 9

The quotation marks are very important, particularly with the inline code starting r

Answers


  1. The date appears as we'd expect underneath the main title

  2. Although the date is still in the YAML it is overwritten by the YAML code chunk to today's date

  3. The date is the same but this uses a function with a more user-friendly name - which do you prefer?

6 / 9

Inline code - formatting in the YAML

3

7 / 9

Friendly date formats

"`r format(Sys.time(), '%d %B %Y')`"
8 / 9

Friendly date formats

"`r format(Sys.time(), '%d %B %Y')`"

Screenshot of the date format being date, month in full and the year

8 / 9

Next section...

9 / 9

Inline code

1

2 / 9

Combining code with text!!

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