I want to parameterise the following computation using dplyr
that finds which values of Sepal.Length
are associated with more than one value of Sepal.Width
:
library(dplyr)
iris %>%
group_by(Sepal.Length) %>%
summarise(n.uniq=n_distinct(Sepal.Width)) %>%
filter(n.uniq > 1)
Normally I would write something like this:
not.uniq.per.group <- function(data, group.var, uniq.var) {
iris %>%
group_by(group.var) %>%
summarise(n.uniq=n_distinct(uniq.var)) %>%
filter(n.uniq > 1)
}
However, this approach throws errors because dplyr
uses non-standard evaluation. How should this function be written?
dplyr
is much nicer:names_with_underscores
.myArray.length
in javascript), is there another conflict in R?some.class.method
a methodsome
of classclass.method
or is it a methodsome.class
of classmethod
? Furthermore, it leads to inconsistent names when parts of your code are implemented in C(++), since that doesn’t support dots in names, necessitating mapping the backend function names to different R names.