I have two functions that evaluate ellipses arguments as column names. These functions (sub_fun_1 and sub_fun_2) use these column names to group the inputted data-frames.
main_fun <- function(df1, df2, ...) {
columns <- enquos(...) ### '...' arguments used to specify columns in data-sets
df1_grouped <- sub_fun_1(df1, columns) ### Evaluates 'columns' and groups df1 by column names
df2_grouped <- sub_fun_2(df2, columns) ### Evaluates 'columns' and groups df2 by column names
}
sub_fun_1 <- function(df1, columns) {
df1_grouped <- df1 %>%
group_by(!!! columns)
}
sub_fun_2 <- function(df2, columns) {
df2_grouped <- df2 %>%
group_by(!!! columns)
}
However, I cannot use the same column names for both data-sets, as that would result in an error, i.e. both data-sets will need to be grouped by column names unique to them.
Is there a way I can specify which ellipses arguments correspond to which function/data-frame? Or possibly use two unique sets of ellipses arguments?
I found some similar questions/answers pages, but am still confused on the topic and how to best implement a solution toward my particular problem.