Вы можете использовать @
или slot
:
#define new s4 class
myS4Class <- setClass(
"myS4Class",
slots = c(
slot1 = "character",
slot2 = "numeric"
)
)
#make an instance of the class
x <- new("myS4Class", slot1 = "foo", slot2 = rnorm(5))
x
теперь можно индексировать, как показано ниже:
x@slot1
#> [1] "foo"
slot(x, "slot2")
#> [1] 0.2391963 -0.3398150 2.1760187 1.1890521 -0.1659958