class: title-slide, center, middle <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #ffffffcc;"></i> <strong class="fa-stack-1x" style="color:#e7553c;">05</strong> </span> # Inline code --- class: inverse, center, middle # <center>Inline code</center> <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#17a2b8;">1 </strong> </span> ??? Combining code with text!! --- # <center>Inline text formatting</center> .pull-left[ 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)` ``` ] ??? The following code will run from a dataset generated in the previous section of Code Chunks: ```r top_viewers <- ratings %>% filter(series == 1) %>% top_n(1, viewers_7day) ``` .pull-right[ Same word: `function` </br> The top viewed episode in series 1 was episode 5 ] ??? 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. --- class: inverse, center, middle # <center>Inline code - in the YAML</center> <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#17a2b8;">2 </strong> </span> --- class: your-turn # Your turn In the file `01-bakeoff-report.Rmd` 1 Add the following in the YAML and 🧶 **Knit** ```yaml --- date: '2022-01-01' --- ``` 2 Replace the date with this code ```yaml --- date: '`r Sys.Date()`' --- ``` 3 Replace the date with this code ```yaml --- date: '`r lubridate::today()`' --- ```
03
:
00
??? The quotation marks are very important, particularly with the inline code starting `r` --- class: your-turn # Answers </br> 1. The date appears as we'd expect underneath the main title 1. Although the date is still in the YAML it is overwritten by the YAML code chunk to today's date 1. The date is the same but this uses a function with a more user-friendly name - which do you prefer? --- class: inverse, center, middle # <center>Inline code - formatting in the YAML</center> <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#17a2b8;">3 </strong> </span> --- # <center>Friendly date formats</center> .pull-left[ ```r "`r format(Sys.time(), '%d %B %Y')`" ``` ] -- .pull-right[ ![Screenshot of the date format being date, month in full and the year](images/format-date-yaml.PNG) ] --- class: inverse # <center>Next section...</center>