From saikat at stat.wisc.edu  Thu Oct  9 15:17:26 2003
From: saikat at stat.wisc.edu (Saikat DebRoy)
Date: Thu Oct  9 20:15:41 2003
Subject: [Rd] S4 group generic Complex not working (PR#4483)
In-Reply-To: <Pine.LNX.4.44.0310091725400.12863-100000@gannet.stats>
Message-ID: <D5E403C7-FA84-11D7-92F4-0003931A3C9E@stat.wisc.edu>

On Thursday, Oct 9, 2003, at 12:46 US/Eastern, Prof Brian Ripley wrote:

> On Thu, 9 Oct 2003 saikat@stat.wisc.edu wrote:
>
>> The Complex group generic for S4 methods is not working:
>>
>>> setClass('foo', representation(z='complex'))
>> [1] "foo"
>>> setMethod('Complex', 'foo', function(z) callGeneric(z@z))
>> [1] "Complex"
>>> Arg(new('foo', z=1+0i))
>> Error in Arg(new("foo", z = 1 + (0+0i))) :
>>          non-numeric argument to function
>>>
>
>> The fix is to add
>>
>>      if (DispatchGroup("Complex", call, op, args, env, &x))
>> 	return x;
>>
>> near the beginning of do_cmathfuns in complex.c.
>
> I don't think that's right: that would set up an S3 group generic
> Complex, and there is no such thing.  That's not how S4 group generics 
> are
> implemented, according to ?Complex.
>

The problem may be with setGroupGeneric. Here is one example where it 
is not working.

 > setGroupGeneric('Finite', function(x) NULL, c('is.finite', 
'is.infinite', +  'is.na', 'is.nan'))
[1] "Finite"
 > setClass('foo', representation(x='numeric'))
[1] "foo"
 > setMethod('Finite', 'foo', function(x) callGeneric(x@x))
[1] "Finite"
 > is.finite(1)
[1] TRUE
 > is.finite(new('foo', x=1))
logical(0)
 >


[Rd] S4 group generic Complex not working (PR#4483)
Saikat DebRoy