Jim Robison-Cox
1998-Jun-17 18:22 UTC
extra arguments to generic functions & bug in model.frame
R developers, 2 things: a bug in model.frame and a question about setup of generic functions. I don't understand the following behavior for generic functions: Suppose I'm working with the cats data in the MASS library and I want to create a formula object to model Hwt on Sex: # This works:> formula(Hwt ~ Sex)Hwt ~ Sex # But the following does not:> formula(Hwt ~ Sex, data = cats)Error in formula.formula(Hwt ~ Sex, cats) : unused argument to function # because I used an extra argument. The odd thing to me, is that formula() itself allows the argument:> formulafunction (x, ...) UseMethod("formula") But formula.default does not:> args(formula.default)function (x) The same thing happens with terms:> args(terms)function (x, ...)> args(terms.default)function (x) And this caused me a problem when using model.frame() since model.frame.default includes the lines: if (!inherits(formula, "terms")) formula <- terms(formula, data = data) Using 2 arguments in term() is a bug since hitting the line will cause an error: Error in terms.default(formula, data = data) : unused argument to function Summary: 1. There seems to be a bug in model.frame() using terms() with 2 arguments. 2. What is standard practice for setting up instances of a generic function? It seems sensible to me that argument lists should not shrink when going from the generic function to an instance of that function. Cheers, Jim Jim Robison-Cox ____________ Department of Math Sciences | | phone: (406)994-5340 2-214 Wilson Hall \ BZN, MT | FAX: (406)994-1789 Montana State University | *_______| Bozeman, MT 59717 \_| e-mail: jimrc@math.montana.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
1998-Jun-17 18:41 UTC
extra arguments to generic functions & bug in model.frame
Jim Robison-Cox <jimrc@mathfs.math.montana.edu> writes:> 1. There seems to be a bug in model.frame() using terms() with 2 arguments.Yes.> 2. What is standard practice for setting up instances of a generic function? > It seems sensible to me that argument lists should not shrink when > going from the generic function to an instance of that function.No. There's no limit to what special parameters a specific instance of a function may implement. So the generic one is generally (x,...). There's no reason not to allow a specific function to check that it is getting called with parameters that make sense. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Douglas Bates
1998-Jun-17 18:44 UTC
extra arguments to generic functions & bug in model.frame
Jim Robison-Cox <jimrc@mathfs.math.montana.edu> writes:> The odd thing to me, is that formula() itself allows the argument: > > formula > function (x, ...) > UseMethod("formula") > > But formula.default does not: > > > args(formula.default) > function (x) > > The same thing happens with terms: > > args(terms) > function (x, ...) > > args(terms.default) > function (x)I would say this is a mistake in the definition of terms.default and formula.default. It is a good programming practice to ensure that the generic and any methods have exactly the same calling sequence. Any such incompatibilities will have to be eliminated from S-PLUS because S version 4, the language on which S-PLUS 5.0 will be based, requires that they have exactly the same calling sequence. S4 doesn't produce an error if you define an "old-style" method with a different calling sequence because it is not recognized as a method. However, when you try to use such a method you get an error if the calling sequence does not match the calling sequence of the generic. BTW, my version of S-PLUS defines the formula function as > formula function(object, ...) UseMethod("formula") > formula.default function(object) We should change the name "x" to "object" to make it easier for people to port code. -- Douglas Bates bates@stat.wisc.edu Statistics Department 608/262-2598 University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._