Re: [Rd] S4 initialize or "generating function"

From: Seth Falcon <>
Date: Wed 31 Jan 2007 - 15:04:11 GMT

Thomas Petzoldt <> writes:

> Hello,
> 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
> things?

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 use new("MyClass",...).

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 duplication.

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 constructors.

+ seth

[*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. mailing list Received on Thu Feb 01 02:06:42 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 31 Jan 2007 - 16:31:08 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.