我对dplyr
的惊人新体验是,如果我对涉及非引号(tibble
或!!x
)的rlang::UQ(x)
进行各种操作,则将它们分配给变量并最终合并他们bind_rows
一切都很好;嵌入bind_rows
的相同操作失败并出现一些错误。更令人困惑的是,错误并不总是一样:我得到quote(x) must resolve to integer column positions, not formula
(这是select
和mutate
)和Column quote(x) is of unsupported type quoted call
(这与group_by
)。我想知道这种行为背后是什么,我做错了什么或者这是一个错误?
require(dplyr)
f1 <- function(d, var){
qvar <- enquo(var)
d1 <- d %>% group_by(!!qvar) %>% summarize_all(first)
d2 <- d %>% group_by(!!qvar) %>% summarize_all(first)
bind_rows(d1, d2)
}
f2 <- function(d, var){
qvar <- enquo(var)
bind_rows(
d %>% group_by(!!qvar) %>% summarize_all(first),
d %>% group_by(!!qvar) %>% summarize_all(first)
)
}
d <- data.frame(
x = c(rep('a', 3), rep('b', 3)),
y = seq(6)
)
f1(d, x) # works
f2(d, x) # fails