【发布时间】:2019-01-20 08:50:33
【问题描述】:
当我尝试在 S4 类中使用 tbl_df 时,tbl_df 插槽似乎被转换为 list。
library('tibble')
setOldClass(c('tbl_df', 'tbl', 'data.frame'))
setClass(Class = 'TestClass', slots = c(name = 'character'), contains = 'tbl_df')
tmp1 <- new('TestClass', tibble(x = 1:5, y = 1, z = x ^ 2 + y), name = 'firsttest')
tmp1@.Data
[[1]]
[1] 1 2 3 4 5
[[2]]
[1] 1 1 1 1 1
[[3]]
[1] 2 5 10 17 26
我可以像访问tbl_df 对象一样访问tmp1@.Data 吗?喜欢
tmp1@.Data
# A tibble: 5 x 3
x y z
* <int> <dbl> <dbl>
1 1 1 2
2 2 1 5
3 3 1 10
4 4 1 17
5 5 1 26
【问题讨论】: