From ggrothendieck at gmail.com  Fri Sep  9 15:08:12 2005
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 9 Sep 2005 09:08:12 -0400
Subject: [Rd] two almost identical packages: best practice
In-Reply-To: <8B2D83C0-69CF-48DA-BF80-98ECC67AF55B@soc.soton.ac.uk>
References: <8B2D83C0-69CF-48DA-BF80-98ECC67AF55B@soc.soton.ac.uk>
Message-ID: <971536df05090906082f9d59d0@mail.gmail.com>

On 9/9/05, Robin Hankin <r.hankin at noc.soton.ac.uk> wrote:
> Hi
> 
> I have written a whole bunch of methods for objects of class "octonion".
> 
> [
> an octonion is a single column of an eight-row matrix.  Octonions have
> their own multiplication rules and are a generalization of quaternions,
> which are columns of a four-row matrix.
> ]
> 
> So far I've done about a dozen generic functions such as seq.octonion(),
> rep.octonion(), [<-.octonion(),  and so on and so on.
> 
> Very nearly all  of these functions are applicable to objects of
> class "quaternion".
> So, for example, I have a generic function Im.octonion():
> 
> R> Im.octonion
> function (x)
> {
>     Re(x) <- 0
>     return(x)
> }
> 
> The definition of Im.quaternion() is exactly the same.
> Sometimes the return value is an octonion:
> 
>  Conj.octonion
> function (x)
> {
>     x <- as.matrix(x)
>     x[-1, ] <- -x[-1, ]
>     return(as.octonion(x))
> }
> 
> So the last line of Conj.quaternion() would be "return(as.quaternion
> (x))"
> but would be otherwise identical.
> A similar story holds for each of maybe twenty generic functions.
> Nearly all the Rd files are similarly identical:  the word "octonion"
> replaces the word  "octonion".  I suppose "A" changes to "An" as well.
> 
> There is a small number of functions and datasets that are specific
> to octonions.
> 
> What is Best Practice in this situation?  I don't want to edit two
> separate
> packages in tandem.   Is there a mechanism for doing what I want
> in the context of a bundle?

Not sure what is best but some possibilities are to:
- create a third S3 class and make your two classes  subclasses of that or 
- make one of your classes a subclass of the other or
- in some cases, you may be able to use the .default method for common code.  
You can also make use of NextMethod if you like though I am not sure if it will
buy you much in this situation (see the dyn package for examples of the use 
of NextMethod).



[Rd] two almost identical packages: best practice
Gabor Grothendieck