[R] S3 and S4 classes

Laurent Faisnel laurent.faisnel at ariase.com
Wed Jul 23 14:53:56 CEST 2003

Hi helpers,

I've been programming in R for a few months now but I still have doubts 
about my code - I would like it to be completely S4-compatible. The 
current code works fine but is probably 'unclean'.
I read the interesting article in the last R News and it helped me 
understand the difference on the whole between S3 and S4 classes, but I 
need a practical example. Could anyone point me out what's S3-like in 
the following sample and why it is not fully S4-compatible ? (any other 
comment welcome).

Thanks in advance.


# I define a class
setClass("MyClass", representation(mynumber="numeric"));

# the initilization method
            .Object at mynumber <- 10;

# a function that objects of this class have
perform <- function(.Object) UseMethod("perform", .Object);

# the associated method
            .Object at mynumber <- .Object at mynumber + 10;

More information about the R-help mailing list