Section 2.11 π‘ Reproducibility Tip:
The
tidyverse provides many ways to work with data, which is both powerful and flexible. To support reproducibility, aim to write code that clearly shows the sequence of transformations applied to your data.
Whenever possible, keep related data-cleaning steps together in a single pipeline rather than creating multiple intermediate objects that are used only once.
For example, consider the following code, which selects variables and filters rows using two separate commands:
penguins_select <- penguins |>
select(species, island, bill_length_mm, body_mass_g)
penguins_new <- penguins_select |>
filter(species == "Adelie")
This creates the intermediate
penguins_select, which is used to create penguins_new. In this case, the same transformation can be expressed more clearly by chaining the steps together:
penguins_new <- penguins |>
select(species, island, bill_length_mm, body_mass_g) |>
filter(species == "Adelie")
Both approaches produce the same result. Keeping related steps together makes it easier to understand how the data were transformed and reduces the number of objects to trackβan important habit for writing clear, reproducible analyses.
