r - 创建包含相同类型插槽的 S4 类
问题描述
作为实践,我正在使用 S4 类在 R 中创建 LinkedList 实现。
我有以下课程:
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"))
推荐阅读
- python - 没有 if 子句的条件?
- java - 需要结合使用 JAXB STAX 的没有结束标记的 XML 根元素
- flutter - flutter redux setState 会调用 oninit 函数并再次刷新页面 #189
- powershell - Powershell:从目录中获取文件和文件夹的计数
- javascript - 如何通过变量名寻址 javascript 类中的静态成员
- memory-management - ESP32 将字符串写入 EEPROM
- php - 我想在 textarea 自定义字段中的 wordpress 中插入链接列表,每个链接都在新行上
- javascript - 如果占位符的属性值包含斜杠和空格,如何使用 querySelectorAll 按属性值进行选择
- amazon-cognito - 使用 amplify auth update 将 Cognito 用户池组添加到现有 Cognito 资源?
- javascript - Jquery onclick功能有时不会触发