Re: [Rd] operators as S4 methods

From: Martin Maechler <>
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         

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 <>
>>>>> 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> mailing list     Iago> mailing list 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