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.
When
fill = "left", not only do NA values get filled in from the left, but the columns are filled in reverse order. Example: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/ydate or anm/ydate) 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.