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

Adds support for spread #72

Closed
wants to merge 2 commits into from

Conversation

edgararuiz-zz
Copy link
Contributor

Adds the following:

  • Initial implementation of tidyr::spread(), for tbl_sql objects

  • A test to confirm that it conforms with the original spread() function

  • NEWS item

@edgararuiz-zz
Copy link
Contributor Author

ptal @hadley

@hadley
Copy link
Member

hadley commented Jun 7, 2018

Hmmmm, I'm not sure I want to start on the tidyr verbs. Is there somewhere more experimental that this could live in the interim?

@edgararuiz-zz
Copy link
Contributor Author

Should we create an interim tidydb package?

R/spread.R Outdated

# Adds a mutate per each unique value
for(vals in 1:length(keys)){
data <- mutate(data, !! expr_text(nf[[vals]]) := !! conds[[vals]])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually I think the operation should be a summarise() instead of mutate(). You can see your result differs from tidyr::spread() if you use the following test data.

df <- tibble(
  h = c("a", "b", "c", "d", "a", "b", "c", "d"),
  x = c("A", "A", "B", "B", "B", "B", "A", "A"),
  y = c("X", "Y", "X", "Y", "X", "Y", "X", "Y"),
  z = c( 1,   2,   3,   4,   5,   6,   7,   8 )
)

@hadley
Copy link
Member

hadley commented Jun 8, 2018

Yeah, I think that's a good idea. Maybe just back it your personal repo for now?

@hadley hadley closed this Jun 8, 2018
@edgararuiz-zz
Copy link
Contributor Author

Sounds good

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

Successfully merging this pull request may close these issues.

None yet

4 participants