Dear Martin and Seth,

Thanks a million for explanations and suggestions. I find myself still in the
process of learning S4 system. Can you possibly suggest some material that I
could use in this "process"?

Anything apart from "Programming with data" book? I also know the notes written
by John Chambers and I also have Fritz Leisch's slides from the first UseR!,
all three available on the Web. Do you have any suggestions in that matter?

Thanks a lot in advance!

Best, Michal

> Martin Morgan <mtmorgan at fhcrc.org> writes:
> 
> > Hi Michal --
> >
> > Add validObject to your initialize method:
> 
> Actually, a call to valid object is part of the default initialization
> method which has been masked.  A different solution, which might have
> some other benefits is to delegate back to the default method using
> callNextMethod.  So you could do:
> 
> setMethod("initialize", "someclass",
> function(.Object, v=numeric(0), l=character(0))
> {
>     # strip the vector names
> 
>     cv <- v
>     cl <- l
>     names(cv) <- NULL
>     names(cl) <- NULL
>     callNextMethod(.Object=.Object, v=cv, l=cl)
> } )
> 
> 
> > Here are two interpretations of this. (1) using 'initialize' means
> > that you are taking control of the initialization process, and hence
> > know when you need to call validObject.
> 
> Yes.  Anytime you specialize a method you must take responsibility for
> any less specific methods.  In this case, the default 'initialize'
> does object validation.  So if you want validation, you either need to
> do it directly or invoke the default method.
> 
> > (2) Responsibility for object
> > validity is ambiguous -- does it belong with 'new', 'initialize', or a
> > 'constructor' that the programmer might write? This is particularly
> > problematic with R's copy semantics, where creating transiently
> > invalid objects seems to be almost necessary (e.g., callNextMethod()
> > in 'initialize' might initialize the inherited slots of the object,
> > but the object itself is of the derived class and could well be
> > invalid 'invalid' after the base class has finished with initialize).
> 
> This is a good point.  It suggests that, at least, one must initialize
> all non-inherited slots to valid values _before_ calling the next
> method.
> 
> + seth



:
::
::: Note that my e-mail address has changed to m.j.bojanowski at uu dot nl
::: Please update you address books accordingly. Thank you!
::
:


____________________________________
Michal Bojanowski
ICS / Department of Sociology
Utrecht University
Heidelberglaan 2; 3584 CS Utrecht
The Netherlands
m.j.bojanowski at uu dot nl
http://www.fss.uu.nl/soc/bojanowski/


        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.

Reply via email to