Not sure if this is the expected behaviour, but split drops custom classes when using the by arg but it keeps them when using the f arg.
library(data.table)
dt = data.table(x = letters[1:10], y = 1:10, z = rnorm(10))
setattr(dt, "class", c("my_class", class(dt)))
# using f
dt |> split(~x) |> lapply(class) |> unlist() |> unique()
#> [1] "my_class" "data.table" "data.frame"
# using by
dt |> split(by = "x") |> lapply(class) |> unlist() |> unique()
#> [1] "data.table" "data.frame"
Created on 2025-06-28 with reprex v2.1.1
Reactions are currently unavailable
Not sure if this is the expected behaviour, but split drops custom classes when using the by arg but it keeps them when using the f arg.
Created on 2025-06-28 with reprex v2.1.1