R 创建包含相同类型插槽的S4类
作为实践,我正在使用S4类在R中创建LinkedList实现 我有以下课程:R 创建包含相同类型插槽的S4类,r,oop,R,Oop,作为实践,我正在使用S4类在R中创建LinkedList实现 我有以下课程: setClass("node", slots = list( value = "numeric", next_node = "node" ), prototype = list( value = NA_real_, next_node = NA ) ) 但是,我收到以下错误消息: Error in makePrototypeFromClassDef(propert
setClass("node",
slots = list(
value = "numeric",
next_node = "node"
),
prototype = list(
value = NA_real_,
next_node = NA
)
)
但是,我收到以下错误消息:
Error in makePrototypeFromClassDef(properties, ClassDef, immediate, where) :
in making the prototype for class “node” elements of the prototype failed to match the corresponding slot class: next_node (class "node" )
In addition: Warning message:
undefined slot classes in definition of "node": next_node(class "node")
您可以使用:
setClass("node",
slots = list(
value = "numeric",
next_node = "nullOrNode"
),
prototype = list(
value = NA_real_,
next_node = NULL
)
)
setClassUnion("nullOrNode", c("NULL", "node"))