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

[FR] gather_all / gather 'smart' default when only key and value given #28

Closed
npjc opened this issue Sep 9, 2014 · 2 comments
Closed

Comments

@npjc
Copy link

npjc commented Sep 9, 2014

example data

df <- structure(list(d = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), l1 = c(1.5, 
1.5, 1.5, 1.5, 1.5, 1.5, 2, 2, 2, 2, 2, 2), l2 = c(1.83333333333333, 
1.83333333333333, 2.16666666666667, 2.16666666666667, 2.5, 2.5, 
2.33333333333333, 2.33333333333333, 2.66666666666667, 2.66666666666667, 
3, 3), l3 = c(2.33333333333333, 2.83333333333333, 2.66666666666667, 
3.16666666666667, 3, 3.5, 2.83333333333333, 3.33333333333333, 
3.16666666666667, 3.66666666666667, 3.5, 4)), class = "data.frame", row.names = c(NA, 
-12L), .Names = c("d", "l1", "l2", "l3"))
head(df)

    d  l1       l2       l3
1   1 1.5 1.833333 2.333333
2   1 1.5 1.833333 2.833333
3   1 1.5 2.166667 2.666667
4   1 1.5 2.166667 3.166667
5   1 1.5 2.500000 3.000000
6   1 1.5 2.500000 3.500000

intention

gather all columns of df into x,y.

current UI

df %>% gather(x, y, d:l3)

request

It would be nice if gather had an all-inclusive default when only key and value arguments are provided. This seems like the most intuitive default to me as I don't think you'd ever want to gather
no columns into a key and value... This would mean that for df the following "smart default" would be equivalent to the current UI (gather all columns).

df %>% gather(x, y)

the select() philosophy

Would this be confusing? Does it go against select()?

Now I think this impacts the whole opposite to the select() paradigm. That is if ... is NULL it current selects nothing... but what is the use case for selecting nothing? There are definitely some use cases for selecting everything ( such as that within gather() ).

In the quest of making code more naturally reader friendly an empty selection giving everything is definitely a negative... so perhaps an alternative solution:

df %>% gather(x, y, all= TRUE)
df %>% gather_all_into(x, y)
df %>% gather_into(x, y)  # think: spread_outof(x,y) to reverse?

but my favorite...

df %>% into(x, y) # opens the door to 'outfrom()` / `outof`
@rpruim
Copy link

rpruim commented Sep 10, 2014

I was going to post a similar thing wondering if gather() could gather all columns when ... is empty.

@hadley
Copy link
Member

hadley commented Sep 24, 2014

This seems reasonable to me.

@hadley hadley closed this as completed in 882b480 Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants