[Rd] print.default and attributes

Mark.Bravington@csiro.au Mark.Bravington@csiro.au
Thu Jan 30 06:17:03 2003

When something gets printed by the "print.default" function, any extra
attributes are printed without regard to their class attribute (if any). For

> x <- 1:3
> attr( x, 'other') <- factor( c( 'cat', 'dog'))
> attr( x, 'other')
[1] cat dog
Levels: cat dog
> x
[1] 1 2 3
[1] 1 2

which is perhaps surprising. Would it be preferable for "print.default" to
call the generic "print" for each attribute, so that any class-specific
print methods are respected?

BTW, the same applies to "print.matrix" (which doesn't rely on "print"), and
perhaps to other print methods. Of course, it will also apply to any
class-specific print method which invokes "print" or "NextMethod", too.

[ Lest this seem incredibly arcane, here's some context: I'm experimenting
(as others have done) with storing documentation in a "doc" attribute. I'd
like to be able to give the "doc" attribute a class so I can control how
it's displayed by a default print, without having to derive a new class &
print method for the object-being-documented. ]



Mark Bravington
PO Box 1538
Castray Esplanade
TAS 7001

phone (61) 3 6232 5118
fax (61) 3 6232 5012