[R] trouble with S4 methods for group "Summary"

From: Parlamis Franklin <fparlamis_at_mac.com>
Date: Thu 29 Dec 2005 - 16:52:00 EST

Hello. This question concerns the Methods package. I have created a new class and am trying to set a method for it for S4 group generic "Summary". I have run into some signature problems. An example:

> setClass("track", representation(x="numeric", y="character"))

	[1] "track"

> setGeneric("max", group="Summary")
[1] "max"
> setMethod("Summary", signature(x="track"), function(x, ..., na.rm)
callGeneric(x@x, ..., na.rm)) [1] "Summary"
> dd<-new("track", x=c(1,2), y="abc")
> max(dd)
[1] -Inf Warning message: no finite arguments to max; returning -Inf
> showMethods("max")
Function "max": na.rm = "ANY" na.rm = "track" na.rm = "missing" (inherited from na.rm = "ANY")

As you can see from the above, the method I tried to set for "max" (via "Summary") was defined for the formal argument "na.rm" not "x". This makes sense because the standardGeneric created for max only allows methods to be defined for argument "na.rm"

> max

	standardGeneric for "max" defined from package "base"
   	belonging to group(s): Summary
	function (..., na.rm = FALSE)
	<environment: 0x19447a28>
	Methods may be defined for arguments: na.rm

However, group "Summary" purports to allow you to define methods for arguments "x" and "na.rm".

> Summary

        groupGenericFunction for "Summary" defined from package "base"         

	function (x, ..., na.rm = FALSE)
	stop("function 'Summary' is a group generic; do not call it directly",
	    domain = NA)
	<environment: 0x16aef098>
	Methods may be defined for arguments: x, na.rm

How does this work? Can someone point me to where I am going wrong, and explain how to define S4 methods for group "Summary" for argument "x"? Perhaps I need to do more in my "setGeneric" call? Thanks in advance.

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Dec 29 17:03:59 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:42 EST