Skip to content

Conversation

atusy
Copy link
Contributor

@atusy atusy commented Aug 5, 2020

unnest_wider on Date class columns fail unless simplify = FALSE is set.

df = tibble::tibble(x = list(c(a = as.Date("2020-01-01"), b = as.Date("2020-01-02"))))
tidyr::unnest_wider(df, x)
#> Error in as.Date.default(value): do not know how to convert 'value' to class "Date"
tidyr::unnest_wider(df, x, simplify = FALSE)
#> # A tibble: 1 x 2
#>   a          b         
#>   <date>     <date>    
#> 1 2020-01-01 2020-01-02

Created on 2020-08-05 by the reprex package (v0.3.0)

As far as I investigated, the issue comes from this line:

x[n == 0] <- list(NA)

Following reprex shows that list(NA) cannot be converted to class "Date" whereas NA can be.

x = c(a = as.Date("2020-01-01"), b = as.Date("2020-01-02"))
x[1] <- list(NA)
#> Error in as.Date.default(value): do not know how to convert 'value' to class "Date"
x[1] <- NA

Created on 2020-08-05 by the reprex package (v0.3.0)

In this PR, I suggest substitute elements by list(NA) if x is a list, and by NA otherwise.

@atusy
Copy link
Contributor Author

atusy commented Aug 5, 2020

It seems like rectangling Date class had been supported before 4b4e516

@atusy atusy force-pushed the unnest-wider-dates branch from 593c989 to 4899f94 Compare August 5, 2020 23:11
@hadley
Copy link
Member

hadley commented Feb 18, 2021

Possibly related to #1089

@hadley hadley closed this in 99b94ee Feb 18, 2021
@hadley
Copy link
Member

hadley commented Feb 18, 2021

I took a slightly different approach — I don't understand exactly why, but in this case x isn't a list, so we don't need to attempt simplification at all.

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.

2 participants