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.
Cheers, Thibaut. -- ###################################### Thibaut JOMBART CNRS UMR 5558 - Laboratoire de Biométrie et Biologie Evolutive Universite Lyon 1 43 bd du 11 novembre 1918 69622 Villeurbanne Cedex Tél. : 04.72.43.29.35 Fax : 04.72.43.13.88 [EMAIL PROTECTED] http://lbbe.univ-lyon1.fr/-Jombart-Thibaut-.html?lang=en http://pbil.univ-lyon1.fr/software/adegenet/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.