Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top_n parameter 'wt' does not work #426

Closed
andrewla opened this issue May 14, 2014 · 0 comments
Closed

top_n parameter 'wt' does not work #426

andrewla opened this issue May 14, 2014 · 0 comments

Comments

@andrewla
Copy link

@andrewla andrewla commented May 14, 2014

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)

mnel added a commit to mnel/dplyr that referenced this issue Jun 16, 2014
Fix Issue tidyverse#426 by using `missing` which does not evaluate it's argument(s)
@mnel mnel mentioned this issue Jun 16, 2014
@hadley hadley closed this in 04f0c83 Aug 1, 2014
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant