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

痞子三分冷 提交于 2019-11-30 01:59:40

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
    

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!