[Rd] S4 methods semantics questions

From: Byron Ellis <ellis_at_stat.harvard.edu>
Date: Fri 25 Mar 2005 - 10:30:01 GMT


Some quick questions about S4 methods.

Does the typing of S4 methods mean that lazy evaluation is no longer possible? It seems that you would need to evaluate the arguments to determine their type at dispatch.

Second, what role, if any, do default arguments play in S4 methods? I notice that you can put default arguments into generics but that the dispatch is still done on the type of the calling argument rather than the default argument, though the default arg is substituted. However, default values for arguments in method definition seem to be stripped or, more likely, overridden at dispatch by the calling argument (i.e. "missing").

Some examples:

setGeneric("foo",function(x="bar") standardGeneric("foo")) setMethod("foo","missing",function(x) print(x))

>foo()

[1] "bar"

setGeneric("foo",function(x,y) standardGeneric("foo")) setMethod("foo","numeric",function(x,y=2) x+y)

>foo(1)

Error in foo(1) : argument "y" is missing, with no default

---
Byron Ellis (ellis@stat.harvard.edu)
"Oook" -- The Librarian

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Mar 25 21:32:56 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:02 GMT