[R] Re: Making a new generic {was "Save method"}

Ernesto Jardim ernesto at ipimar.pt
Fri Nov 8 10:25:48 CET 2002


Thanks for your answer. You're absolutly rigth, it's written on the
manuals so I should check it first.

I'm sorry if I wasted your time.



On Fri, 2002-11-08 at 08:34, Martin Maechler wrote:
> >>>>> "Ernesto" == Ernesto Jardim <ernesto at ipimar.pt>
> >>>>>     on 07 Nov 2002 15:43:02 +0000 writes:
>     Ernesto> I want to use save methods but I found that the
>     Ernesto> save function is not a generic function ...
>     Ernesto> If I define 
>     Ernesto> save <- function(x, ...)
>     Ernesto> UseMethod("save")
>     Ernesto> I'll be overwriting the original save function ...
>     Ernesto> Is there another way of doing this ? or am I
>     Ernesto> understanding it wrong ?
> ``As always'' you find the answer to this question in the 
> "R Extensions" / "Writing R Extensions (including C & Fortran)"
> manual.  Look for the section  ``Adding new generics''.
> Yes, please read that in the full context (you'll learn things
> that you should rather learn now than later).
> But for the sake of .., the crucial excerpt is
>  RExt>    Sometimes package writers want to make generic a function in the base
>  RExt> package, and request a change in R.  This may be justifiable, but
>  RExt> making a function generic with the old definition as the default method
>  RExt> does have a small performance cost.  It is never necessary, as a package
>  RExt> can take over a function in the base package and make it generic by
>  RExt> 
>  RExt>      foo <- function(object, ...) UseMethod("foo")
>  RExt>      foo.default <- get("foo", pos = NULL, mode = "function")
> Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
> Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
> ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
> phone: x-41-1-632-3408		fax: ...-1228			<><

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list