andrewla · GitHub

Something is broken in the substitution of the wt parameter in the top_n helper function.

> iris %.%
+  group_by(Species) %.%
+  summarise(w=mean(Petal.Width)) %.%
+  top_n(1, w)
Error in top_n(`__prev`, 1, w) : object 'w' not found

The equivalent spelled out with filter(rank(...)) works fine

> iris %.%
+  group_by(Species) %.%
+  summarise(w=mean(Petal.Width)) %.%
+  filter(rank(w) <= 1)
Source: local data frame [1 x 2]
  Species     w
1  setosa 0.246

My experience with R at this level is limited, but I'm pretty sure the problem is that we're evaluating is.null(wt) at the beginning of the function; and adding wt <- substitute(wt) at the beginning will defer the evaluation sufficiently for this to work. EDIT: or using missing(wt) instead of is.null(wt)

Read the original on github.com ↗