Skip to content

: Operator overloading for custom classes

3 messages · Peter Ruckdeschel, Chidambaram Annamalai

3 days later
#
First of all you should read about S4 classes, in particular
the books of John Chambers should be helpful ;-)
(others on this list might point you to further sources).

The key is to define S4 classes for your operands
[i.e; if I have understood correctly you would implement
your Dual number class as S4 class].

Then you would define new methods by setMethod().

Not sure whether this gives you the indications you look for,
but we have overloaded arithmetic operators to act on distribution
classes in package distr (cf CRAN, developped under r-forge).
You might want to look at the code in NormalDistribution.R resp.
ContDistribution.R

HTH Peter Ruckdeschel