library(tidyverse)library(nycflights13)
Chapter 4. Workflow: Code Style
Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread. Even as a very new programmer, it’s a good idea to work on your code style. Using a consistent style makes it easier for others (including future you!) to read your work and is particularly important if you need to get help from someone else. This chapter will introduce the most important points of the tidyverse style guide, which is used throughout this book.
Styling your code will feel a bit tedious to start with, but if you practice it, it will soon become second nature. Additionally, there are some great tools to quickly restyle existing code, like the styler package by Lorenz Walthert. Once you’ve installed it with install.packages("styler"), an easy way to use it is via RStudio’s command palette. The command palette lets you use any built-in RStudio command and many addins provided by packages. Open the palette by pressing Cmd/Ctrl+Shift+P and then type styler to see all the shortcuts offered by styler. Figure 4-1 shows the results.

Figure 4-1. RStudio’s command palette makes it easy to access every RStudio command using only the keyboard.
We’ll use the tidyverse and nycflights13 packages for code examples in this chapter.
Names
We talked briefly about names in “What’s in a Name?”. Remember ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access