Re: [Rd] S4 helper functions: regular or generic?

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Wed, 25 Feb 2009 06:36:08 -0800

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 25 Feb 2009 - 13:41:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 04 Mar 2009 - 02:30:52 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive