Skip to content
Prev 31801 / 63424 Next

Could you please add "time<-" as a generic function in the 'stats' package ?

Whatever one wants for an S3 generic, it's not needed to do what, 
presumably, you want here.

And for sure it is no excuse for S3 methods for S4 classes.

Back to basics: To write S4 methods for an existing function, the clean 
and simple way is usually:

setGeneric("time<-")

If your package depends on one that has S3  methods for this function, 
there will be a version of the function imported into your namespace.  
That function will then be the default method.

Presumably you want to ensure that S3 methods, for S3 classes, are still 
dispatched.  Quite reasonable and it should follow from the call to 
setGeneric.

If you wanted to have your own S3 methods or if you weren't willing to 
assume an S3 generic imported, you could do a 2-line version:

R(r48103)> `time<-` <- function(x, value) UseMethod("time<-")
R(r48103)> setGeneric("time<-")
[1] "time<-"
R(r48103)> showMethods("time<-", include = TRUE)
Function: time<- (package .GlobalEnv)
x="ANY"
function (x, value)
UseMethod("time<-")

As a postscript, here is the current plan, not yet committed, pending 
some more testing:
  - the bad methods will be allowed
  - warnings when a class is defined with such methods for a superclass
  - probably some other warnings, but not for an ordinary call to the 
method (it's the MISSING calls to the method that are the disaster).

More later,
  John
Yohan Chalabi wrote: