[R] Extracting Coefficients and Such from mle2 Output

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Feb 2 02:08:34 CET 2009

A minor footnote to Ben's response.

Why is it *supposed* to be harder to get bits out of objects like this and why should you work through accessor functions?  ("If it works, why shouldn't I use it?" - why indeed.)

The answer I would give is that if you work through the official accessor functions provided by the package, then your code stands a good chance of working even if the author of the package decides to change the representation of the object in future releases.  That's why your should steer clear of using anything that relies on the internal details of an object and not just the public face presented.  

This strategy also makes your code easier for someone else to follow.  Your intentions become clearer.

Bill Venables

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ben Bolker
Sent: Monday, 2 February 2009 10:18 AM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] Extracting Coefficients and Such from mle2 Output

Marc Schwartz <marc_schwartz <at> comcast.net> writes:

> on 02/01/2009 10:45 AM David Winsemius wrote:
> > Let me  admit at this point that I am not really sure that S4 classes is
> > the correct classification of such "@"-using extraction processes. The
> > documentation refers to "formal methods" and I don't yet have enough
> > knowledge to know that how tightly slots and formal classes are linked
> > with S4 or S3.
> David,
> The use of '@' as a slot extractor is specific to S4 methods and you
> will actually get an error if attempting to use it on other object
> types. As per the Details section of ?"@":

  My other two cents about this issue:

 David is quite right that you can basically think of "@"
as equivalent to "$" for getting bits out of S4 objects.
However ... in general S4 classes make it harder to get
internal bits out of objects, and in some sense they're
really *supposed* to make it harder.  Really the thing to
do when you encounter information that's buried somewhere
in an S4 object, the appropriate solution is what you did --
write to the author and say "why isn't there an accessor
method [the technical jargon for functions like coef()]
to get this piece of information out of this object, or
why isn't it properly documented? (Or is there some 
reason that I shouldn't be trying to access this piece
of information?)"

   Ben Bolker

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list