My surprising new experience with dplyr
is if I do various manipulations on tibble
s involving unquotes (!!x
or rlang::UQ(x)
), then assign them to variables and finally merge them by bind_rows
it works all fine; while the same manipulations embedded into bind_rows
fail with some error. More confusingly the error is not always the same: I got quote(x) must resolve to integer column positions, not formula
(this was with select
and mutate
) and Column quote(x) is of unsupported type quoted call
(this with group_by
). I am wondering what is behind this behaviour, I do something wrong or is this a bug?
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