[Rd] operators as S4 methods

Martin Maechler maechler at stat.math.ethz.ch
Tue Jun 14 10:13:26 CEST 2005

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

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 <imosqueira at 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 at r-project.org mailing list
    Iago> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list