[R] Who to decide what a generic function should look like?
Frank E Harrell Jr
fharrell at virginia.edu
Thu Feb 20 12:42:03 CET 2003
On Thu, 20 Feb 2003 13:05:44 +1100
Henrik Bengtsson <hb at maths.lth.se> wrote:
> I am not sure if what I am asking below should be discussed under r-help
> or r-devel, so please feel free to move over to r-devel.
> This is a spin off from Gordon Smyth's question about generic functions
> and Robert Gentleman's reply. I have tried to raise the question before
> and I am sure this has been discussed by others, but never on the r-help
> list what I can see. My concern is that generic functions as defined
> today are only semi-generic. From ?Methods the definition of a generic
> function is:
> "A generic function is a function that has associated with it a
> collection of other functions (the methods), all of which agree in
> formal arguments with the generic."
> For me a generic function should be fully generic in the sense that
> there are no requirements of arguments agreement (and therefore it
> should not be documented as a reply to Smyth's thread). Under the
> S3/UseMethod scheme as well S4/methods scheme this requirement is
> enforced (even though one can get around it by using only arguments
> "...") and under S4/methods it is followed even more strictly. I
> understand that by enforcing matching arguments (and argument types) the
> method dispatching mechanism can work much faster. Are there any another
> purposes than efficiency behind the argument matching requirement? Why
> not make a generic function truly generic? Having truly generic
> functions, the method dispatching mechanism could equally well be done
> by the language interpreter itself and thus making generic functions
. . .
> Henrik Bengtsson
I agree completely with Henrik about the problems caused by argument agreement. This has caused me a great deal of trouble. As an example, I have many functions for converting S objects to LaTeX, with parallel functions for printing or plotting. If I latex( ) a regression model fit, the types of LaTeX options that apply are drastically different than if I latex( ) a data frame for making a table with minor and major groupings. A very small number of arguments are in common. I tried converting latex( ) to use the new methods some time ago, and had to abondon the effort to large extent because of this problem.
Frank E Harrell Jr Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine http://hesweb1.med.virginia.edu/biostat
More information about the R-help