Paul Gilbert
Fri, 16 Apr 1999 15:08:45 -0400

> since I don't have a summary.level1 function (which you may

Whoops, I missed a part:

summary.level1 <- function(object)
{ r<- "level1"
  class(r) <- "summary.level1"

print.summary.level1 <- function(x) { cat(x) }

>  You haven't really said what you want to do in enough detail for
>  me to give you an answer.
>    If an object has several class attributes then NextMethod is
>  a way to move down the heirarchy.

I guess my first question was a very general one: Is this approach to moving
through the heirarchy to  construct a summary and print it likely to be fairly
robust as R and S evolve? Despite my lack of detail I think you answered that in
general it is.

Some of your other comments made me realize that my whole understanding of class
heirarchy is not good. In particular, I had thought of a more specific class
something like a sub-class: a specific class being associated with a particular
general class.  An object could be  c("level2a", "level1") or c("level2b",
"level1") but it would not logically be c("level2", "level1a") or c("level2",

>From what you've said I guess that is wrong. The class heirarchy should be
associated only with a specific object, not thought of as a logical structure
for all objects having their most specific class in common.

So, in my example

summary.level1.level2 <- function(object)
{ r <- list("level2 before")
  r <- append(r,NextMethod("summary"))
  r <- append(r,"level2 after")
  class(r) <- "summary.level1.level2"

I could replace NextMethod("summary") with summary.level1(object) because I know
that any object of class "level1.level2" always inherits from "level1". (This is
part of the reason for my naming convention "level1.level2" for the specific
class.) But if I did this replacement and then called summary with an object of
class c("level1.level2", "level1b"), I would get a different result.
My way of thinking about this has not caused me any problems, I just have not
used inheritance  to its full power.

If I still have this all wrong please let me know.

Paul Gilbert

r-devel mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: