From ross at biostat.ucsf.edu  Tue Jan 19 22:26:42 2010
From: ross at biostat.ucsf.edu (Ross Boylan)
Date: Tue, 19 Jan 2010 13:26:42 -0800
Subject: [Rd] calling setGeneric() twice (don't; documentation comments)
In-Reply-To: <4B561C33.8080901@userprimary.net>
References: <1263924060.10417.31.camel@corn.betterworld.us>
	<4B55F45C.4040408@userprimary.net>
	<1263928770.10417.52.camel@corn.betterworld.us>
	<4B561C33.8080901@userprimary.net>
Message-ID: <1263936402.10417.66.camel@corn.betterworld.us>

On Tue, 2010-01-19 at 12:55 -0800, Seth Falcon wrote:
> I would expect setGeneric to create a new generic function and
> nuke/mask 
> methods associated with the generic that it replaces.
I tried a test in R 2.7.1, and that is the behavior.  I think it would
be worthwhile to document it in ?setGeneric.

Also, ?setGeneric advocates first defining a regular function (e.g.,
bar) and then doing a simple setGeneric("bar").  I think the advice for
package developers is different, so perhaps some changes there would be
a good idea too.

I thought I was defining setGeneric twice for a few functions, and thus
that it did work OK.  It turns out I have no duplicate definitions.

Here's the test:
> setClass("A", representation(z="ANY"))
[1] "A"
> setClass("B", representation(y="ANY"))
[1] "B"
> setGeneric("foo", function(x) standardGeneric("foo"))
[1] "foo"
> setMethod("foo", signature(x="A"), function(x) return("foo for A"))
[1] "foo"
> 
> a=new("A")
> b=new("B")
> foo(a)
[1] "foo for A"
> foo(b)
Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "foo", for signature "B"
> setGeneric("foo", function(x) standardGeneric("foo"))
[1] "foo"
> setMethod("foo", signature(x="B"), function(x) return("foo for B"))
[1] "foo"
> 
> setGeneric("foo", function(x) standardGeneric("foo"))
[1] "foo"
> setMethod("foo", signature(x="B"), function(x) return("foo for B"))
[1] "foo"
> foo(a)
# here's where the disappearance of the prior setMethod shows
Error in function (classes, fdef, mtable)  : 
  unable to find an inherited method for function "foo", for signature "A"
> foo(b)
[1] "foo for B"

So I guess I am going to pull the setGeneric's out.
Ross



[Rd] calling setGeneric() twice (don't; documentation comments)
Ross Boylan