class - 从 S4 类定义中的包中识别 S3 (?) 类

标签 class r definition s4

我在从 S4 类定义识别的旧包中获取类时遇到了一些麻烦。我不断收到错误

Error in makePrototypeFromClassDef(properties, ClassDef, immediate, where) : 
  in making the prototype for class "Tsvmm" elements of the prototype failed to 
  match the corresponding slot class: dates (class "dates" )
In addition: Warning message:
undefined slot classes in definition of "Tsvmm": dates(class "dates") 

一个可重现的例子:
require(chron)

setClass(
  Class="Tsvmm",
  representation=representation(
      data  = "data.frame",
      dates = "dates"
  ),
  prototype=prototype(
      data  = data.frame(),
      dates = chron(0)
  )
)

尝试时 class(chron(0)) ,答案是"dates" "times" .使用 is.numeric(chron(0)) ,答案是TRUE .然而,当我将插槽日期的类设置为 "numeric" 时,我收到相同的错误,但没有警告消息。

我感觉我忽略了一些明显的东西,但我还没有在文档中找到它。有人有任何指点吗?

PS:我知道chron包至少是奇特的,但我有充分的理由使用它。另外,这个问题很可能发生在其他包上。将此视为一般问题的示例。所以请不要告诉我使用 Date 或 POSIXt 类。这是我现在正在使用的黑客。

最佳答案

看来你需要setOldClass让方法相信日期是一个真正的类。

关于class - 从 S4 类定义中的包中识别 S3 (?) 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4400867/

相关文章:

r - GGplot2 中面板背景的条件格式

r - 如何使用 rvest 检索 google 搜索中的超链接

c - 如何在 C 中定义函数数组

terminology - 什么是垫片?

java - 为什么 toString() 不能是静态方法?

c++ - 在 C++ 中重载运算符时,如何解决从 'const double*' 到 'double*' 的无效转换

node.js - 编译后从 typescript 命名空间导出类给出未定义(NestJS)

r - 使用SparkR,如何将字符串列拆分为 'n'多列?

definition - "legacy code"的定义是什么?

PHP:如何在数据库对象上使用准备?