Skip to content
Prev 8366 / 12125 Next

[R-pkg-devel] Dispatch for S3 and Ordinary Function with Same Name

On 29.08.2022 17:00, Dario Strbenac wrote:
Idealy do not define a new predict which is a generic function in  R.

Rather, you methods may produce objects that follow,e g.g., the classes 
provided by randomForest plus eventiually extra elements.
Then you invent a new class name, e.g. moreRandomForest that inherits 
from randomForest:

...
class(x)  <- c("moreRandomForest", "randomForest")

if you provide your own moreRandomForest method for predict, dispatch 
will choose it, if you do not provide it, mathod dispatch will choose 
the one from the pterh package. Please simply read some introductory 
material about S3.


Best,
Uwe Ligges
Message-ID: <607f57f5-c736-85ad-7f62-33115e03b78e@statistik.tu-dortmund.de>
In-Reply-To: <SY2PR01MB300376E48BB4307783EBF4E9CD769@SY2PR01MB3003.ausprd01.prod.outlook.com>