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

Saikat DebRoy saikat at stat.wisc.edu
Thu Oct 9 15:17:26 MEST 2003


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

> On Thu, 9 Oct 2003 saikat at 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 at 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 at x))
[1] "Finite"
 > is.finite(1)
[1] TRUE
 > is.finite(new('foo', x=1))
logical(0)
 >



More information about the R-devel mailing list