Skip to content
Prev 15843 / 63461 Next

Overloading methods in R

Thanks a lot Tony. I am trying to apply the overloading to the methods 
created by R.oo package and, unfortunately, R.oo uses S3-style classes; so I 
cannot use the features of S4 methods as you described. On the other hand, I 
caouldn't find a decent OO package which is based on S4 AND comes with the 
official release of R.

Assume we have this class created using R.oo:

-------------------------
require(R.oo)

setConstructorS3("SomeClass",
    function(...)
    {
        extend(Object(), "SomeClass");
    }
);

setMethodS3(
    "fun",
    "SomeClass",
    function(this, x, ...)
    {
        paste(x);
    }
);
-------------------------

Now if we overload the method by:

-------------------------
setMethodS3(
    "fun",
    "SomeClass",
    function(this, x, y, ...)
    {
        paste(x, y);
    }
);
-------------------------

then R.oo overwrites the method 'fun' with the new definition. As the 
overloaded methods share the same class, it is not possible to use the 
function overloading method as you described.

I hope there is some other way to handle this problem.