[R] Summary method needed?

Martin Maechler maechler at stat.math.ethz.ch
Thu Aug 3 11:25:46 CEST 2006

>>>>> "HeinzT" == Heinz Tuechler <tuechler at gmx.at>
>>>>>     on Thu, 03 Aug 2006 09:39:35 +0100 writes:

    HeinzT> At 21:04 02.08.2006 +0100, Prof Brian Ripley wrote:
    >> On Wed, 2 Aug 2006, Christian Hennig wrote:
    >>> Thank you Brian!
    >>> > > I'm updating my fpc package at the moment and will add some new functions.
    >>> > > I learned that there should be print and summary methods for the key
    >>> > > functions.
    >>> >
    >>> > for 'classes', I think.
    >>> Yes.
    >>> > > But in some cases the print method will make use of
    >>> > > more or less all the output information of the
    >>> > > function. Is there any reason to implement a summary
    >>> > > method in these cases?
    >>> >
    >>> > Would a more concise print() method be useful?  If so
    >>> > the existing print() could become summary().
    >>> :-)

    >>> What I initially did some years ago was to write summary
    >>> methods to print out the required informations. Then
    >>> M. Maechler told me that this is not the purpose of a
    >>> summary method and I should write a print.summary method
    >>> for this. Now I realise that I actually just want to
    >>> print, and I don't really need the extra "synopsis" to
    >>> be done by summary().
    >>> Now is there any recommendation on this? My intuition
    >>> would be to write a print, but not a summary method.
    >> That sounds fine for your purposes.

    HeinzT> Maybe I am wrong, but as far as I see, print() has
    HeinzT> the disadvantage that it has to return x and must
    HeinzT> not return the summarized results as an object.  You
    HeinzT> remember the difficulties with print.survfit.

    HeinzT> Instead it seems to be allowed that summary does not
    HeinzT> only print but also return summarized results.

    HeinzT> Is that right?

yes, that's right,  But let me tell more on the story:

I think I had recommended  summary.FOO() and print.summary.FOO()
to Christian because he *did* compute a few `useful' things on
his "FOO" object. In such a situation, we (R-core) recommend and
usually (very rarely not; for back-compatibility reasons only) implement
the following:

print.FOO: gives a one (sometimes two) paragraph overview of
	   the fitted model object, and
	   --yes-- *should* return its *unchanged* argument invisibly.

summary.FOO: computes more interesting things from the original
	     FOO object, does *NOT print* anything (explicitly)
	     and returns an object of class "summary.FOO".

print.summary.FOO: now prints (an overview of) the summary.FOO
	     object and -- since it's a print() method -- also
	     returns its argument unchanged and invisibly.

  Examples of the above, can be inspected e.g., for 
  'FOO' in  { lm, glm, aov, nls, loess, princomp, prcomp, ...... }

For Joe Average User, of course it *looks* like 
summary( <FOO> ) would print , but that's just because it
returns a summary.FOO object which is auto-printed subsequently
-- unless it's assigned or used in another expression.

My reasons for *not* providing a  summary.* and print.summary.*
method would have to be either *both* of 1) and 2)  *or* 3) :

1) print(obj) gives enough information 

2) the 'obj' already contains the interesting quantities, or
   these are either trivially computable from the contents of 'obj'
   or are already provided by other FOO methods, e.g., vcov.FOO().

3) lack of time and/or motivation; lazyness

Martin Maechler, ETH Zurich

More information about the R-help mailing list