-
Notifications
You must be signed in to change notification settings - Fork 417
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
unnest errors when data.table's IDate class is combined with integers #1507
Comments
Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session. |
@hadley done. thanks! |
Hmmm, that works for me: library(tidyr)
library(data.table)
df_idates <- tibble(
ids= c(1, 2),
data = list(
tibble(
dates = c(as.IDate('2012-01-01'), as.IDate('2013-12-03'), as.IDate('2023-06-03')),
),
tibble(
numbers = 1:3
)
)
)
df_dates <- tibble(
ids= c(1, 2),
data = list(
tibble(
dates = c(as.Date('2012-01-01'), as.Date('2013-12-03'), as.Date('2023-06-03')),
),
tibble(
numbers = 1:3
)
)
)
unnest(df_idates, 'data')
#> # A tibble: 6 × 3
#> ids dates numbers
#> <dbl> <IDate> <int>
#> 1 1 2012-01-01 NA
#> 2 1 2013-12-03 NA
#> 3 1 2023-06-03 NA
#> 4 2 1970-01-02 1
#> 5 2 1970-01-03 2
#> 6 2 1970-01-04 3
unnest(df_dates, 'data')
#> # A tibble: 6 × 3
#> ids dates numbers
#> <dbl> <date> <int>
#> 1 1 2012-01-01 NA
#> 2 1 2013-12-03 NA
#> 3 1 2023-06-03 NA
#> 4 2 NA 1
#> 5 2 NA 2
#> 6 2 NA 3 Created on 2023-11-01 with reprex v2.0.2 |
Hmm. Those 1970 dates in the IDate result shouldn't be there though, right? |
Oh yeah, that is weird! Slightly more minimal reprex: library(tidyr)
library(data.table)
df <- tibble(
ids = c(1, 2),
date = list(tibble(x = as.Date('2012-01-01')), tibble(y = 1)),
idate = list(tibble(x = as.IDate('2012-01-01')), tibble(y = 1)),
)
unnest(df, c(date, idate), names_sep = "_")
#> # A tibble: 2 × 5
#> ids date_x date_y idate_x idate_y
#> <dbl> <date> <dbl> <IDate> <dbl>
#> 1 1 2012-01-01 NA 2012-01-01 NA
#> 2 2 NA 1 1970-01-02 1
unnest_wider(df, c(date, idate), names_sep = "_")
#> # A tibble: 2 × 5
#> ids date_x date_y idate_x idate_y
#> <dbl> <date> <dbl> <IDate> <dbl>
#> 1 1 2012-01-01 NA 2012-01-01 NA
#> 2 2 NA 1 NA 1 Created on 2023-11-01 with reprex v2.0.2 Interesting that |
Looks like something is going wrong deep in the bowels of |
Tracking in r-lib/vctrs#1892, it's a vctrs issue |
unnest
errors when data.table's IDate class is combined with integers.unnest
is capable of handling situations where nested tibbles contain dates and integers, but it fails when it attempts the same thing with data.table'sIDate
class.Created on 2023-11-01 by the reprex package (v2.0.1)
I am using the latest GH version of tidyr.
The text was updated successfully, but these errors were encountered: