是否可以不为 s4 插槽设置类型

Is it possible to not set types for s4 slots

我想达到的目标

为了构建一个通用框架,我想构建一个带有插槽的 s4 class,插槽可以是任何类型。可能吗?如果是的话怎么办?

到目前为止我发现了什么

我找到了 this 个解决多类型问题的问题。但我想让任何类型成为可能,而不仅仅是一些预定义的类型。

示例:

setClass("foo",
         representation(
           anything = "..."
         )
)

# I would like to be able to perform all of these
new("foo", anything = 1)
new("foo", anything = "a")
new("foo", anything = data.frame())
...

是的,你可以这样做:

setClass("hi", slots = c(slot1 = "ANY"))

ANY的使用其实在帮助中有记载