从 S4 类定义中的包中识别 S3 (?) 类
我在从 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 类。这是我现在正在使用的一个技巧。
I have some troubles getting a class from an older packages been recognized by the S4 class definition. I keep on getting the error
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")
A reproducible example:
require(chron)
setClass(
Class="Tsvmm",
representation=representation(
data = "data.frame",
dates = "dates"
),
prototype=prototype(
data = data.frame(),
dates = chron(0)
)
)
When trying class(chron(0))
, the answer is "dates" "times"
. using is.numeric(chron(0))
, the answer is TRUE
. Yet, when I set the class of slot dates as "numeric"
, I get the same error without the warning message.
I have the feeling I'm overlooking something obvious, but I couldn't find it in the documentation yet. Anybody any pointers?
PS: I know the chron
package is at least peculiar, but I have good reasons to use this. Plus, the problem is likely to occur with other packages. See this as an example for a general question. So please, don't tell me to use the Date or POSIXt classes. That's a hack I'm using now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您需要 setOldClass 使方法相信日期是一个真正的班级。
It seems that you need setOldClass to make methods believe dates is a real class.
我遇到了类似的问题,因为 Gtk2 对象(例如,Gtk2::GtkBuilder)不是 S4 类,而我希望在我自己的代码中拥有这样一个对象的一个实例。我想我通过删除原型()的东西并使用“initialize()”方法来解决这种情况。
I've got a similar problem because Gtk2 objects (e.g., Gtk2::GtkBuilder) are not S4 classes whereas I wanted one instance of such an object in my own code. I think I worked arround a the situation by removing the prototype() thing and using an "initialize()" method.