R-ecology-lesson icon indicating copy to clipboard operation
R-ecology-lesson copied to clipboard

Consider switching to base R pipe?

Open jcblum opened this issue 6 months ago • 5 comments

How could the content be improved?

There was some previous discussion about whether to adopt the base R pipe (|>) instead of the magrittr pipe (%>%). There was a suggestion to wait to see whether the base R pipe gained traction among R users, and especially in the tidyverse community.

I think this discussion is worth re-opening, since it remains relevant to the new lesson content, which uses the magrittr pipe and does not mention the existence of the base R pipe at all.

Some relevant developments:

  • Base R's |> pipe is now the only pipe mentioned in the tidyverse style guide.

  • The second edition of R for Data Science chose to primarily recommend the base R pipe, with this explanation, which also seems relevant to Carpentries learners:

    For simple cases, |> and %>% behave identically. So why do we recommend the base pipe? Firstly, because it’s part of base R, it’s always available for you to use, even when you’re not using the tidyverse. Secondly, |> is quite a bit simpler than %>%: in the time between the invention of %>% in 2014 and the inclusion of |> in R 4.1.0 in 2021, we gained a better understanding of the pipe. This allowed the base implementation to jettison infrequently used and less important features.

  • Now that R 4.5 has been released, all versions of R supported by the tidyverse versioning policy include the base R pipe. The need to support older versions of R was a key factor keeping the magrittr pipe in use in tidyverse documentation, so I'd expect the shift to using |> for tidyverse documentation may accelerate.

  • There is a checkbox in RStudio settings where you can choose which pipe to use for keyboard shortcuts, but the default is still %>% in order to support R <=3.6 (relevant issue to track). If this lesson were to switch to |> before RStudio changes its default, changing this setting might need to be included as part of the lesson, or part of setup.

If this lesson switches to using |>, it would probably be a good idea to include an aside about the magrittr pipe (much as R4DS did), since novice learners will still encounter it in lots of existing online content.

Conversely, if this lesson does not switch to |> soon, it would probably be a good idea to at least add an aside about the base R pipe, since novice learners will increasingly encounter it in online content and package documentation.

Which part of the content does your suggestion apply to?

https://datacarpentry.github.io/R-ecology-lesson/working-with-data.html#the-pipe

jcblum avatar Apr 11 '25 21:04 jcblum