0

Can someone explain why in the following code (taken from Hadley, R for Data Science, Chapter 13, print, First Edition)

library(tidyverse)

mtcars %>% split(.$cyl) # Works
mtcars |>  split(.$cyl) # Does not work

the third line throws an error saying

#Error in split.data.frame(mtcars, .$cyl) : object '.' not found

I thought that the pipe %>% and the native pipe |> could be used interchangeably. Using R.4.2. Is it generally a bad idea to use the native pipe implemented in RStudio?

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
minimouse
  • 131
  • 10
  • 2
    You can use underscore as a placeholder in the latest version of R – Allan Cameron May 28 '22 at 10:54
  • 3
    2nd/work-in-progress edition of Hardley's R4DS includes section *"5.3 |> vs %>%"* - https://r4ds.hadley.nz/workflow-pipes.html#vs . It's up to date, describes `_` placeholder and it's current limitations (i.e not supporting operators like `$`, `[[`, `[` with `_`) – margusl May 28 '22 at 11:00
  • 1
    Thanks for all your your answers. The third comment by "marusl" was very helpful. Thanks again to the community! – minimouse May 28 '22 at 11:10

0 Answers0