以下代码产生错误:
setClass(Class ='Foo', slots=c(field_1='character', field_2 = 'character' ))
list_of_obj <- c(new('Foo', field_1 = 'bar', field_2 = 'foo_bar'))
list_of_obj[1]@field_1
Error: trying to get slot "field_1" from an object of a basic class ("list") with no slots
如何访问列表中存储的对象中的插槽field_1
?
答案 0 :(得分:1)
使用双括号访问列表的元素, 单括号将为您提供一个列表对象
list_of_obj[[1]]@field_1
[1] "bar"