2

My surprising new experience with dplyr is if I do various manipulations on tibbles 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
deeenes
  • 4,148
  • 5
  • 43
  • 59
  • Voting to close, because this problem cannot be reproduced. Both `f1` and `f2` calls work fine for me with R 3.5.3 and dplyr 0.8.0. – Artem Sokolov May 02 '19 at 20:09
  • Well, it was an error with dplyr `0.7.x`, got no answer here, but apparently got fixed since then. – deeenes Jan 20 '21 at 14:26

0 Answers0