From ripley at stats.ox.ac.uk  Fri Oct 10 09:42:29 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri Oct 10 09:41:46 2003
Subject: [Rd] S4 group generic Complex not working (PR#4483)
In-Reply-To: <3F85AD1A.5DB6B895@research.bell-labs.com>
Message-ID: <Pine.LNX.4.44.0310100835520.16936-100000@gannet.stats>

On Thu, 9 Oct 2003, John Chambers wrote:

> 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.
> 
> For arguments that might have methods, DispatchGroup first tries to
> dispatch an S4 method, then if none is found goes on to look for an S3
> method.
> 
> The choice would seem to be:  (1) allow both S4 and S3 group methods for
> Complex (& revise current documentation); or (2) special-case the code
> in DispatchGroup to skip S3 methods when argument `group' matches
> "Complex".
> 
> Preferences?

It makes sense to introduce a S3 group for Complex, and although that 
would be a new feature I guess it would be acceptable in a patch release 
as a side-effect of a bug fix.

Is this all that is wrong though?  I failed to set a method for Arg 
directly, but am not sure I am awake enough to have done it right:

> setClass('foo', representation(z='complex'))
[1] "foo"
> setMethod("Arg", "foo", function(z) Arg(z@z))
[1] "Arg"
> Arg(new('foo', z=1+0i))
Error in Arg(new("foo", z = 1 + (0+0i))) : 
        non-numeric argument to function


> 
> John
> 
> > 
> > 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.
> > 
> > --
> > Brian D. Ripley,                  ripley@stats.ox.ac.uk
> > Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> > University of Oxford,             Tel:  +44 1865 272861 (self)
> > 1 South Parks Road,                     +44 1865 272866 (PA)
> > Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> > 
> > ______________________________________________
> > R-devel@stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
> 
> 

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


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