将 `tidyeval` 与 exposition pipe 操作符一起使用

问题描述

我似乎无法弄清楚如何将 %$% 中的 magrittr 运算符与 tidyeval 一起使用。以下是此问题的可重现性最低的示例:

tabletidyeval

之外的说明运算符一起使用
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 函数)没有。 这就是为什么整洁评估适用于前者而不适用于后者。这与管道操作符无关。