Re: [R] Standard method for S4 object

From: Thibaut Jombart <>
Date: Sun, 24 Feb 2008 19:10:37 +0100

Martin Morgan wrote:

> Christophe Genolini wrote:
>>> Personnally I would find stuff like "names", "$", "$<-", or "["
>>> useful as these are usual operation with S3 objects.
>> Is it possible in S4 to define "$<-" ? If there is a slot name 'a' in
> Possible yes, see below. Usual? It implies to the user that this is a
> list- or data.frame-like object (where $ is used most commonly). Maybe
> your object is not like that? It also seems like a short step from
> direct slot access (although it doesn't have to be), which might be
> breaking the abstraction layer that object orientation provides. And
> it shifts the responsibility for confirming that 'name' is a slot, and
> dispatching on different values of 'name' (e.g. for some slots perhaps
> one doesn't want to allow access, and then the code inside the '$'
> method has to check that), back to the developer (instead of allowing
> the method definition and dispatch to do its work). Generally these
> seem like backward steps to me.
Yes, to me too. But it is nonetheless useful when you convert an 'old' S3 class to S4 and want to re-use your old code as much as possible (or want users to be able to do so). I don't know if this is the case here. Plus, as $ and $<- are just wrappers for @ and @<-, the procedure checking the validity of a value assigned to a slot is still called when using $<-. Another, maybe interesting option is to use accessors to change the values of the slots. This might be more object-oriented, and would allow for more control on the content of the object.



CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive
Universite Lyon 1
43 bd du 11 novembre 1918
69622 Villeurbanne Cedex
Tél. :
Fax :

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 24 Feb 2008 - 18:13:06 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 Sun 24 Feb 2008 - 18:30:16 GMT.

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

list of date sections of archive