Session - styling code
An updated version of R4DS now includes a section on code style
It particularly mentions the package {styler} which, when run becomes an addin to RStudio, and automatically applies the tidyverse style to code
RStudio also automatically indents according to the function bracket positions
Highlighting line of code using the keyboard shortcut Ctrl+i
applies indents
beds_data
then press return, where does the cursor go?beds_data |>
then return, where does the cursor go now?beds_data |> select(org_name, org_code)
and put the select on a new line, then put org_code
onto a new line.Ctrl+i
:08:00
Using spaces helps with readability
The code below will run as R doesn’t need spaces to work:
Putting the spaces in can be effort after it’s been written
Firstly copy the code without spaces to the document
With {styler} loaded library(styler)
go to the Add in drop down menu and select Style Active File
05:00