Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recognizing a S3 (?) class from a package in an S4 class definition

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.

like image 222
Joris Meys Avatar asked Feb 25 '23 15:02

Joris Meys


1 Answers

It seems that you need setOldClass to make methods believe dates is a real class.

like image 85
Romain Francois Avatar answered Feb 28 '23 16:02

Romain Francois