1

I used the "." a lot to work with pipes chains in R and dplyr. However, now old code seems to now work anymore with that syntax. I could not find any answers on google. What am I missing?

Here is a silly example just to explain what I am referring to:

test <- iris |> 
  select(Sepal.Length, Sepal.Width)

random <- data.frame(
  Sepal.Length = sample(iris$Sepal.Length), 
  Sepal.Width = sample(iris$Sepal.Width)) |> 
  bind_rows(., test) |> 
  ggplot(aes(x=Sepal.Length, y=Sepal.Width)) +
  geom_point()

The code above used to work, but now it fails with an error that "." was not found.

  • 6
    `|>` is the base pipe operator. You're confusing it with the magrittr pipe which is `%>%`. See https://stackoverflow.com/questions/67633022/what-are-the-differences-between-rs-new-native-pipe-and-the-magrittr-pipe – Ritchie Sacramento Dec 13 '22 at 00:09
  • 4
    `|>` is not the `dplyr` pipe, it is the new 'native' pipe. – George Savva Dec 13 '22 at 00:09
  • Ahhh! Got it! Ok so if I use the new "native" pipe dplyr is not called? Is there any way to use the new native pipe and still invoke the dplyr package? Just out of curiosity – Fabio Favoretto Dec 13 '22 at 00:12
  • 1
    You can definitely use the native with `dplyr` tools. `dplyr` is telling you, "why, why, why???, I already know you want to drag that last value forward!" (In other words, use `|> bind_rows(test) |>` instead. (You do have to call the `dplyr` library, though!) – Kat Dec 13 '22 at 00:54
  • 3
    Starting in R-4.2, it is possible to use the `_` _similar_ (but not the same) to how magrittr's `.` works, the key differences being that `_` must be used for a named argument and that it can be used only once (per function call), whereas `.` can be used arbitrarily (named or not) and multiple times. https://stackoverflow.com/q/67633022/3358272 has some good discussion about this topic. – r2evans Dec 13 '22 at 02:37
  • Thank you @Kat and Evans for your answers as well!! – Fabio Favoretto Dec 13 '22 at 17:12

0 Answers0