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

separate with fill = "left" reverses column order #170

Closed
dgrtwo opened this Issue Feb 28, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@dgrtwo
Member

dgrtwo commented Feb 28, 2016

When fill = "left", not only do NA values get filled in from the left, but the columns are filled in reverse order. Example:

library(tidyr)

d <- data.frame(x = c("1-2-3", "2-3", "3"))

# I understand this behavior
separate(d, x, c("a", "b", "c"))
#> Warning: Too few values at 2 locations: 2, 3
#>   a    b    c
#> 1 1    2    3
#> 2 2    3 <NA>
#> 3 3 <NA> <NA>

# here, surprised that 3 and 2 are reversed:
separate(d, x, c("a", "b", "c"), fill = "left")
#>      a    b c
#> 1    1    2 3
#> 2 <NA>    3 2
#> 3 <NA> <NA> 3

I think this is undocumented since the docs for fill only say that NAs are filled from the left, not that the values will be reversed. I also think the most common use case would be splitting a column where there is an optional first value (like either a d/m/y date or an m/y date) and can't think of a use case where reversing the order only when there aren't enough values would be helpful.

It seems like changing it would be a straightforward change here, but I don't know if this is desired behavior. I'm happy to PR it myself.

@hadley

This comment has been minimized.

Member

hadley commented May 16, 2016

Yeah, that's definitely a bug. I'd love a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment