%。%(dplyr)和%>%(magrittr)之间的差异 [英] Differences between %.% (dplyr) and %>% (magrittr)
问题描述
dplyr
包引入了%。%
运算符作为函数的参数传递左侧在右侧,类似于* NIX管。 magrittr
包是一个更轻便的包,它只存在于管道式操作符。
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 pipe. The magrittr
package is a much more lightweight package that exists to define only that pipe-like operator.
使用%。%
和另一个%>%
。
两者有区别吗?即使在 dplyr
代码中,我可以使用%>%
,还是会导致微妙的错误?
Is there any difference between the two? Can I just use %>%
even in dplyr
code, or will that cause subtle bugs?
在检查代码时,他们早期采取非常不同的路径,所以简单的眼球比较表明它们是不同的。我没有找到任何记录的文件,当我搜索他们的网页,也没有在文档本身的任何东西。
On inspecting the code, they take very different paths early on, so simple eyeball comparison would suggest that they're different. I haven't been able to find anything documented when I search the web for them, nor have I run across anything in the documentation itself.
推荐答案
差异包括
-
您可以使用
。
as左边的占位符,例如
you can use a
.
as placeholder for the left-hand side, e.g.
iris %>% plot(Sepal.Length ~ Sepal.Width, data = .)
%>%
尊重 rhs)
,例如
1:10 %>% (call("sum"))
1:10 %>% (function(x) x^2 + 2*x)
更有用的
例如,请参阅
https://gist.github.com/anonymous/0c69b019d0b4f6ae5050
对于
单参数函数调用,可以省略括号:
For single argument function calls, you can omit parens:
"2014-05-18" %>% as.Date
这篇关于%。%(dplyr)和%>%(magrittr)之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!