library(dplyr)
library(lubridate)
# given
my_groups <- ordered(c("year", "month", "day"))
test_df <- data.frame(dates = Sys.Date() + days(1:180), ints = 1:180) %>% mutate(year = year(dates), month = month(dates), day = day(dates))
# would like to be able to get the following result:
test_df %>% group_by_("year", "month") %>% summarise(sum = sum(ints))
# but would like to be able do so programmatically, as in the two failing code examples below:
## this fails
test_df %>% group_by_( my_groups[my_groups >= "month"]) %>% summarize(sum = sum(ints))
## i think it's a quoting issue, but something like this also fails
test_df %>% group_by_( paste(my_groups[my_groups >= "month"], collapse = ", ")) %>% summarize(sum = sum(ints))
test_df %>% group_by_(.dots = as.character(my_groups[my_groups >= "month"])) %>% summarize(sum = sum(ints))