Home Comments Thread
New Thread

Substitute the magrittr Pipe `%>%` with R’s Native Pipe Operator `|>` | /en/2022/04/magrittr-native-pipe/

giscus giscus 2024-11-08 08:21:54

R 4.1.0 has added a native pipe operator |> to base R. If you are using the magrittr pipe %>% and want to switch to |> in your R scripts (you do not have to), I have a quick function …

https://yihui.org/en/2022/04/magrittr-native-pipe/

1 Comment

fingitt fingitt 2024-11-08 08:21:55

Nice tool, Yihui! I noticed a few more cases in which it doesn't work:

  1. In some places R expects a comma after an item. If you put a line of comment there, it gets converted to invisible(...) without a trailing comma and breaks the formatter. E.g.:
x <- c(
  # a is not used
  a = 0
)
  1. Sometimes R doesn't accept the ( after invisible, e.g., if you have a comment inside a function declaration like this:
x <- function(
  # First argument does nothing
  a = 1
) {
  0
}
yihui yihui 2024-11-08 15:26:40

That's the same issue as yihui/formatR#103

Sign in to join the discussion

Sign in with GitHub