I don't know why passing argument from custom function to group_by
doesn't work. I just pass a colName
from dataset and when I run my own function then error comes up: Must group by variables found in .data.
Column 'colName' is not found. In my example below I use quakes
dataset available in R environment:
foo <- function(data, colName) {
result <- data %>%
group_by(colName) %>%
summarise(count = n())
return(result)
}
foo(quakes, "stations")
# I also tried passing w/o commas but it is not working too:
# foo(quakes, stations)
I noticed, that when I pass column name explicitly to group_by
then it works:
group_by(stations) %>%
However, it doesn't make sense to hardcode column name in function..