[R] Overloading %*%

From: Joe Cainey <jcainey_at_gmail.com>
Date: Sun, 16 Mar 2008 19:18:47 +0000


Is it possible to supply a new method for the %*% operator? I need to provide a new method for working on variables of a newly defined class,
"ad". I've had no problems overloading +, * etc.., using code such as:

"+.ad" <- function(a,b = NULL)


    # further code here

I've tried to do the same thing with %*%:

"%*%.ad" <- function(a,b)


    # further code here

However this doesn't work; the new method is never called and the standard %*% operator is used instead. I've had a look at the documentation and it appears to be because the %*% operator is not part of the "Math", "Ops",
"Summary" or "Complex" groups. I was wondering if anybody knew of a
work-around for this?

(I realise that I can just do %*%.ad(a,b) when I want to use the new method, but it would be much better for me if I could find something more transparent.)


Joe Cainey

        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 16 Mar 2008 - 19:23:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 16 Mar 2008 - 21:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive