tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.77k stars 2.12k forks source link

In tally_ and count_, support programmatic specification of wt #1919

Closed dholstius closed 7 years ago

dholstius commented 8 years ago

Passing the name(s) of variables (as character) "just works" in most underscored ("programmatic") dplyr functions. For example:

tally(group_by_(my_data, "foo"), wt = bar)

But, it looks like this has yet to be supported in tally_ (and hence, also in count_).

Proposed: these should also work:

tally_(my_data, wt = "bar")
count_(my_data, vars = "foo", wt = "bar")

Happy to construct test cases, pull request, etc. but not sure if this might be intended behavior — or if/how it intersects with the intended behavior of lazyeval::interp (relied upon by tally_).

krlmlr commented 8 years ago

@hadley: I agree that this is inconsistent, and wt should accept both character and formula in tally_(). The inconsistencies are even more severe in tidyr.

hadley commented 8 years ago

@krlmlr yes, I think we'll definitely want to take another pass at this for the next release (using everything we've learned in lazyeval etc)

hadley commented 7 years ago

@lionel- another one for you

lionel- commented 7 years ago

Should this be tally(my_data, wt = !! symbol("bar"))?

@hadley what's the rule for which verbs should support strings? group_by() supports strings but select() does not.

hadley commented 7 years ago

Yes, I think so.

I think generally verbs shouldn't support strings without some syntactic signal. select() has one_of(), and with tidyeval we can now use !!.

lionel- commented 7 years ago

sounds good, closing this then.