Closed jakeybob closed 4 months ago
Period objects and similar "multi-column" structures are not supported by data.table, as described in https://github.com/Rdatatable/data.table/issues/4415. I don't think there's anything we can do on the dtplyr end.
Notice the length of the "start" slot when subsetting a data frame vs when subsetting a data.table. Subsetting the data.table (rather than just a column) produces an error.
suppressPackageStartupMessages({
library(lubridate)
library(data.table)
library(dplyr)
})
df <- tibble(a = 1:3) |>
mutate(interval = interval(start = ymd("2024-01-01") - days(a), end = ymd("2024-01-01")))
dt <- as.data.table(df)
str(df[3, 'interval', drop = TRUE])
#> Formal class 'Interval' [package "lubridate"] with 3 slots
#> ..@ .Data: num 259200
#> ..@ start: POSIXct[1:1], format: "2023-12-29"
#> ..@ tzone: chr "UTC"
str(dt[3, interval])
#> Formal class 'Interval' [package "lubridate"] with 3 slots
#> ..@ .Data: num 259200
#> ..@ start: POSIXct[1:3], format: "2023-12-31" "2023-12-30" ...
#> ..@ tzone: chr "UTC"
dt[3]
#> Error in dimnames(x) <- dn: length of 'dimnames' [1] not equal to array extent
Created on 2024-07-21 with reprex v2.0.2
OK, thanks, appreciate the reply -- I wasn't aware of the underlying workings and multi-col structures etc; good to know!
Hi -- I've encountered an issue where
dtplyr
seems to fail when filtering data that has alubridate::interval()
column. I saw this originally on a tibble of ~50 columns, of various different data types (including several lubridate date/time etc types), and dropping the singleinterval()
column seemed to fix it -- so it does seem to be specific to interval data.I've submitted here (rather than as a lubridate issue) as it happens when the filtering is done with respect to other data (here an integer column).
It's easy enough to work around, but figured I'd raise an issue as the behaviour seems unexpected. Any thoughts appreciated! :smiley:
sessionInfo()