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

pull() to collect a single column #2054

Closed
krlmlr opened this issue Aug 5, 2016 · 5 comments
Closed

pull() to collect a single column #2054

krlmlr opened this issue Aug 5, 2016 · 5 comments
Labels
feature a feature request or enhancement verbs 🏃‍♀️

Comments

@krlmlr
Copy link
Member

krlmlr commented Aug 5, 2016

For regular data sources, I can do the following to obtain a count as an atomic value:

> data_frame(1:3) %>% tally %>% as.numeric
[1] 3

For SQL sources, I have to insert a collect():

> memdb_frame(a=1:3) %>% tally %>% as.numeric
Error in magrittr(.) : (list) object cannot be coerced to type 'double'
3: traceback(1)
2: magrittr(.) at pipe.R#6
1: memdb_frame(a = 1:3) %>% tally %>% as.numeric
> memdb_frame(a=1:3) %>% tally %>% collect %>% as.numeric
[1] 3

Perhaps we can implement as.numeric.tbl_lazy() and others?

@hadley
Copy link
Member

hadley commented Feb 2, 2017

I think we should implement pull() from lplyr: https://github.com/paulponcet/lplyr. It could default to the first column.

@hadley hadley added database feature a feature request or enhancement labels Feb 2, 2017
@krlmlr
Copy link
Member Author

krlmlr commented Feb 3, 2017

What's special about the first column? Often you want to pull data after applying mutate(), which adds columns at the end.

The verb itself could also have more general mutate semantics: iris %>% pull(Sepal.Length * Sepal.Width) .

@hadley
Copy link
Member

hadley commented Feb 3, 2017

It's just a reasonable default because you often have a single column data frame.

I think I like the idea of allowing it to do inline mutation too.

@krlmlr
Copy link
Member Author

krlmlr commented Feb 3, 2017

If the last column is the default, it will still work for one-column data frames.

@hadley
Copy link
Member

hadley commented Feb 3, 2017

Hmmmm, that just somehow feels less predictable to me. It probably doesn't really matter if we support inline mutate.

@hadley hadley changed the title [SQL] FR: as.numeric() et al. pull() function to collect a single column Feb 14, 2017
@hadley hadley changed the title pull() function to collect a single column pull() to collect a single column Feb 14, 2017
@hadley hadley closed this as completed in 0b9aabf Feb 24, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement verbs 🏃‍♀️
Projects
None yet
Development

No branches or pull requests

2 participants