【发布时间】:2019-03-19 19:06:21
【问题描述】:
如何将字符向量传递给dplyr::count()。
library(magrittr)
variables <- c("cyl", "vs")
mtcars %>%
dplyr::count_(variables)
这很好用,但dplyr v0.8 会引发警告:
count_() 已弃用。 请改用 count()
“编程”小插曲或 tidyeval 书可以帮助您 用 count() 编程:https://tidyeval.tidyverse.org
我在https://tidyeval.tidyverse.org/dplyr.html 或tidyeval book 和Programming with dplyr 的当前版本的其他章节中没有看到引用名称或dplyr::count() 的标准评估示例。
阅读此文档后我的两个最佳猜测和another SO question 是
mtcars %>%
dplyr::count(!!variables)
mtcars %>%
dplyr::count(!!rlang::sym(variables))
抛出这两个错误:
错误:列
<chr>的长度必须为 32(行数)或 1, 不是 2错误:只能将字符串转换为符号
【问题讨论】:
-
改为
!!!rlang::syms(variables)。
标签: r dplyr standard-evaluation