如何解决将 `tidyeval` 与 exposition pipe 操作符一起使用
我似乎无法弄清楚如何将 %$%
中的 magrittr
运算符与 tidyeval
一起使用。以下是此问题的可重现性最低的示例:
table
与 tidyeval
之外的说明运算符一起使用
library(magrittr)
print(mtcars %$% table(am))
#> am
#> 0 1
#> 19 13
table
不适用于带有 tidyeval
的说明运算符
foo <- function(data,x) {
# works with pipe operator
print(data %>% dplyr::pull({{ x }}))
# doesn't with exposition operator
data %$% table({{ x }})
}
foo(mtcars,am)
#> [1] 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1
#> Error in table({: object 'am' not found
解决方法
dplyr::pull
对其参数使用整洁的评估。 table
(作为基本 R 函数)没有。 这就是为什么整洁评估适用于前者而不适用于后者。这与管道操作符无关。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。