[Rd] S4 initialize or "generating function"
sfalcon at fhcrc.org
Wed Jan 31 16:04:11 CET 2007
Thomas Petzoldt <Thomas.Petzoldt at TU-Dresden.de> writes:
> apologies if I missed something well known. I'm just revising an own
> package and wonder if it is still common to use "generating
> functions" which have the same name as the corresponding S4 class as
> suggested by Chambers, 2001. "Classes and Methods in the S Language".
> -- or should one consequently use new and initialize to do such
If you have no inheritence between the classes in your system (and are
pretty sure you are not going to have any) then I don't think it
really matters whether you define MyClass() to create new instances or
There is considerable advantage to having your constructors be real
methods when you do have inheritence relations among your classes.
This allows you to make use of callNextMethod to reduce code
Defining an "initialize" method and using new seems to be the standard
and I suspect is required if you want to plug into the validObject
protocol. The "initialize" setup tries to make some strange
assumptions about how objects should be able to be constructed (IMO) [*1*].
Furthermore, it is a bummer to lose multiple dispatch when defining
[*1*] The default initialize method interprets named arguments as
slots which is a reasonable default, but not always sensible. What I
find quite strange is that an un-named argument is interpreted as an
instance that should be cloned.
More information about the R-devel