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

Emm*_*Lin 1 r s4

我想实现的目标

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

到目前为止我发现了什么

我发现这个问题解决了多类型问题。但是我想让任何类型的对象都可以,而不仅仅是一些预定义的类型。

例:

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())
...
Run Code Online (Sandbox Code Playgroud)

Rol*_*ASc 5

是的,您可以执行以下操作:

setClass("hi", slots = c(slot1 = "ANY"))
Run Code Online (Sandbox Code Playgroud)

采用ANY在帮助实际记录。