Saving metadata on a subset in data.table

I work with data.tablein R that contain metadata (stored in the "comment" attribute), which provides a timestamp for the data. With a subset of data.table, metadata is discarded. For example,

library(data.table)
dt <- data.table(x = c(1:5), y = c(6:10))
setattr(dt, 'comment', 'december 10, 2015')
comment(dt)                  # The metadata is present here...
# [1] "december 10, 2015"
comment(dt[x < 3])           # ...but not retained here
# NULL

data.frame, on the other hand, does not exhibit the same behavior. For example,

df <- data.frame(x = c(1:5), y = c(6:10))
comment(df) <- "december 2015"
comment(df)              # Metadata again is present
# [1] "december 2015"
comment(df[df$x < 3, ])  # Metadata is retained
# [1] "december 2015"

Does anyone know if there is a way to store data.tablemetadata in these subsets?

+4
source share

Source: https://habr.com/ru/post/1613875/


All Articles