data.table 的用户指定属性被移除

User-specified attributes of data.table get removed

我有一个函数 returns data.table 附加了各种有用的用户定义属性。不过,我注意到,当有人操纵 data.table.

时,属性会消失
library(data.table)
my_dt <- data.table(col1 = rnorm(20), col2 = letters[1:20])

# store some user attribute
attr(my_dt, 'title') <- 'This is my data.table'
# now it's there
attributes(my_dt)
# but here it's gone
attributes(my_dt[order(col1)]) 

有什么方法可以为上述情况创建 data.table 'persist' 的属性(除了将它们存储在单独的对象中之外)?

似乎属性确实持续存在于常规 data.frames

my_df <- data.frame(col1 = rnorm(20), col2 = letters[1:20])

# store some user attribute
attr(my_df, 'title') <- 'This is my data.frame'
# there it is
attributes(my_df) 
# still there
attributes(my_df[order(my_df$col1), ]) 

功能已添加到 1.12.0 中,当 Matt 将子集并行化时。所以属性现在被保留。

library(data.table)
my_dt <- data.table(col1 = rnorm(20), col2 = letters[1:20])

attr(my_dt, 'title') <- 'This is my data.table'
attr(my_dt, 'title')
#[1] "This is my data.table"
attr(my_dt[order(col1)], 'title')
#[1] "This is my data.table"