From bates@stat.wisc.edu  Tue Dec  2 16:56:15 1997
From: bates@stat.wisc.edu (Douglas Bates)
Date: Tue, 2 Dec 1997 10:56:15 -0600 (CST)
Subject: R-alpha: NextMethod in 0.50-a4
Message-ID: <m0xcvcN-000hhXC@franz.stat.wisc.edu>

I am encountering difficulty with NextMethod in 0.50-a4.  We created a
class of groupedData objects which are data.frames with additional
attributes.  The most important attribute is a formula describing
roles of some of the variables in the experimental design.

The class of such objects ends in "groupedData", "data.frame".  The
print method for the groupedData class simply cat's the formula then
calls NextMethod.  In R this produces a peculiar message about not
being able to find the function print.groupedData which happens to be
the function that is currently being evaluated.  I tried different
forms of the call to NextMethod but to no avail.

The purpose and design of the groupedData class is described in

@InProceedings{	  bate:pinh:1997,
  author	= {Douglas M. Bates and Jos\'{e} C. Pinheiro},
  title		= {Software Design for Longitudinal Data},
  editor	= {Timothy G. Gregoire},
  booktitle	= {Modelling Longitudinal and Spatially Correlated Data:
		  Methods, Applications and Future Directions},
  year		= 1997,
  address	= {New York},
  publisher	= {Springer-Verlag},
  pages		= {37--48}
}

I created an artificial example using the "acid" data so it can be
reproduced by others.  (BTW, the acid.doc file has a misprint.  The
name of the second column is "optden", not "opt".)

 R> data(acid)
 R> acid
   carb optden
 1  0.1  0.086
 2  0.3  0.269
 3  0.5  0.446
 4  0.6  0.538
 5  0.7  0.626
 6  0.9  0.782
 R> class(acid)
 [1] "data.frame"
 R> attr(acid, "formula") <- optden ~ carb
 R> class(acid) <- c("groupedData", "data.frame")
 R> print.groupedData
 function (x, ...) 
 {
	 cat("Grouped Data: ")
	 print(attr(x, "formula"))
	 NextMethod()
 }
 R> acid
 Grouped Data: optden ~ carb
 Error: couldn't find function "print.groupedData"
 R> print.groupedData <-
 +   function(x, ...)
 + {
 +   cat("Grouped Data: ")
 +   print(attr(x, "formula"))
 +   NextMethod(print, x, ...)
 + }
 R> acid
 Grouped Data: optden ~ carb
 Error: couldn't find function "print.groupedData"
 R> print.groupedData <-
 +   function(x, ...)
 + {
 +   cat("Grouped Data: ")
 +   print(attr(x, "formula"))
 +   NextMethod("print", x, ...)
 + }
 R> acid
 Grouped Data: optden ~ carb
 Error: couldn't find function "print.groupedData"
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


R-alpha: NextMethod in 0.50-a4
Douglas Bates