从 S4 类定义中的包中识别 S3 (?) 类
-
25-09-2019 - |
题
我在从 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"
, ,我得到同样的错误,但没有警告消息。
我感觉我忽略了一些明显的东西,但我在文档中还找不到它。有人指点一下吗?
附:我知道 chron
包至少很奇特,但我有充分的理由使用它。另外,其他软件包也可能出现此问题。将此作为一般问题的示例。所以请不要告诉我使用 Date 或 POSIXt 类。这是我现在正在使用的一个技巧。
解决方案
看来你需要 setOldClass ,使方法认为日期是一个真正的类。
其他提示
我遇到了类似的问题,因为 Gtk2 对象(例如 Gtk2::GtkBuilder)不是 S4 类,而我希望在我自己的代码中拥有这样一个对象的一个实例。我想我通过删除原型()的东西并使用“initialize()”方法来解决这种情况。
不隶属于 StackOverflow