Re: [Rd] operators as S4 methods

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Tue 14 Jun 2005 - 08:13:26 GMT

For arithmetic operators,
the most elegant way often is to define so called `group methods' for the whole group of arithmetic operators.

This actually applies also applies to the old classes and methods.

One example where we do this is the 'Matrix' package, see the source, e.g., in
https://svn.r-project.org/R-packages/Matrix/R/dMatrix.R         

Note that for a namespaced package, on also needs to import the group generics from the 'methods' package in NAMESPACE:

## Currently, group generics need to be explicitly imported: importFrom("methods", Arith, Compare, Math, Math2, Summary, Complex)

Martin Maechler, ETH Zurich

>>>>> "Iago" == Iago Mosqueira <imosqueira@suk.azti.es>
>>>>> on Tue, 14 Jun 2005 09:23:40 +0200 writes:

    Iago> Dear all,
    Iago> I need to re-define some mathematical operators (+, *, /, etc) for an S4
    Iago> class based on array. All references I have found (S Programming, Green
    Iago> Book) show how to define S3 methods for this (like in page 89 of S
    Iago> Programming for "-.polynomial"). What is the preferred S4 way for doing
    Iago> this? I hope I haven't missed some obvious piece of documentation.

    Iago> Many thanks,  

    Iago> Iago Mosqueira

    Iago> ______________________________________________
    Iago> R-devel@r-project.org mailing list     Iago> https://stat.ethz.ch/mailman/listinfo/r-devel

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Jun 14 18:14:58 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:27:18 GMT