Differences between %.% (dplyr) and %>% (magrittr)

前端 未结 2 1061
清歌不尽
清歌不尽 2020-12-25 14:30

The dplyr package introduced the %.% operator to pass the left hand side as an argument of the function on the right hand side, similar to a *NIX p

相关标签:
2条回答
  • 2020-12-25 15:25

    Differences include

    • you can use a . as placeholder for the left-hand side, e.g.

      iris %>% plot(Sepal.Length ~ Sepal.Width, data = .)
      
    • %>% respects (rhs), e.g.

      1:10 %>% (call("sum"))
      1:10 %>% (function(x) x^2 + 2*x) 
      

      For a more useful example of this, see
      https://gist.github.com/anonymous/0c69b019d0b4f6ae5050

    • For single argument function calls, you can omit parens:

      "2014-05-18" %>% as.Date
      
    0 讨论(0)
  • 2020-12-25 15:35

    See the very first item in the current NEWS file:

    dplyr now imports %>% from magrittr (#330). I recommend that you use this instead of %.% because it is easier to type (since you can hold down the shift key) and is more flexible

    0 讨论(0)
提交回复
热议问题