管道操作符“%>%"的使用在 R 中使用 :: [英] use of pipe operator "%>%" using :: in R
问题描述
我正在构建一个 R 包并且我正在大量使用管道运算符 %>%.我想知道如何使用 :: 运算符从 purrr 包中调用它.我试过 purrr::%>%
但出现错误.
I am building an R package and I am using intensively the pipe operator %>%. I am wandering how to call it from purrr package using :: operator. I have tried purrr::%>%
but get an error.
我感谢任何有关此的指南.
I appreciate any guide on this.
P.D:我应该从 magrittr 而不是 purrr 呼叫管道操作员吗?
P.D: should I call the pipe operator from magrittr rather than purrr?
推荐答案
如果您希望您的用户能够访问它,最好的方法是从 magrittr 导入它并重新导出它.
Your best approach is to import it from magrittr and re-export it if you want your users to be able to access it.
仅在您的包内部使用它,这可能有效:
Using it internally to your package only, this may work:
`%>%` <- purrr::`%>%`
检查:
iris %>% summary
Sepal.Length Sepal.Width Petal.Length Petal.Width
Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
Median :5.800 Median :3.000 Median :4.350 Median :1.300
Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
Species
setosa :50
versicolor:50
virginica :50
您不能直接在表达式中使用 purrr::`%>%`
,因为运算符需要在语法上公开为二元运算符,即 %>%
(无资质).
You cannot use purrr::`%>%`
directly in expressions as the operator needs to be syntactically exposed as a binary operator, i.e. as %>%
(without qualification).
这篇关于管道操作符“%>%"的使用在 R 中使用 ::的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!