From grgoswami at gmail.com  Wed Mar  4 03:59:07 2009
From: grgoswami at gmail.com (Gopi Goswami)
Date: Tue, 3 Mar 2009 21:59:07 -0500
Subject: [Rd] S4 helper functions: regular or generic?
In-Reply-To: <6phzlgar3c7.fsf@gopher4.fhcrc.org>
References: <5811e0170902250359k3de97428h8f92f5882dcdab87@mail.gmail.com>
	<6phzlgar3c7.fsf@gopher4.fhcrc.org>
Message-ID: <5811e0170903031859l23069ec4k757c5e924e9dc212@mail.gmail.com>

Dear Martin,


Thanks a lot for your help, apologies for this very late reply. I
decided to go with your suggestion, write a regular function. I guess
this avoids doing

obj <- as(foo(as(obj, 'Base')), 'Derived')

and then repopulating the extra slots of of the 'Derived' class.


Regards,
gopi.


On Wed, Feb 25, 2009 at 9:36 AM, Martin Morgan <mtmorgan at fhcrc.org> wrote:
> Hi Gopi --
>
> Gopi Goswami <grgoswami at gmail.com> writes:
>
>> Hi there,
>>
>>
>> I want to write helper functions for a base class, which will be used
>> by its subclasses in the S4 world. This function ___will___ update
>> certain slots of its argument object. Please help me decide which one
>> of the following is a better approach with respect to coding style,
>> memory usage and speed:
>>
>
> My opinion:
>
>> o ? Write a regular function.
>
> memory and speed
>
>> o ? Declare a generic and implement it just for the base class.
>
> coding 'style', but style is subjective.
>
> There are other aspects of S4, e.g., type checking, method dispatch,
> programmatically defined and discoverable API, ... (positives),
> cumbersome documentation (negative).
>
> My usual pattern of development is to be seduced by the siren of
> speed, only to regret boxing myself in.
>
> I find that my S4 objects typically serve as containers for
> coordinating other entities. ?The important methods typically extract
> R 'base' objects from the S4 class, manipulate them, and repackage the
> result as S4. The time and speed issues are in the manipulation, not
> in the extraction / repackaging. This is contrast to, say, an
> implementation of a tree-like data structure with a collection of
> 'Node' objects, where tree operations would require access to each
> object and would be horribly slow in S4 (and perhaps R when nodes were
> represented as a list, say, at least compared to a C-level
> representation, or an alternative representation that took advantage
> of R's language characteristics).
>
> Martin
>
>>
>> Thanks for sharing your insight and time,
>> gopi.
>> http://gopi-goswami.net/
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Martin Morgan
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M2 B169
> Phone: (206) 667-2793
>



[Rd] S4 helper functions: regular or generic?
Gopi Goswami