Skip to content

Save method

4 messages · Ernesto Jardim, Martin Maechler, Henrik Bengtsson

#
Hi

I want to use save methods but I found that the save function is not a
generic function ...

If I define 

save <- function(x, ...)
UseMethod("save")

I'll be overwriting the original save function ...

Is there another way of doing this ? or am I understanding it wrong ?

Regards

EJ



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Hi

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.

Regards

EJ
On Fri, 2002-11-08 at 08:34, Martin Maechler wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
2 days later
#
Dear all, I have been struggling to find a way of creating generic
functions in a safe way that do not make any assumptions on what
packages have been loaded before my packages are loaded. For this reason
there needs to be some conditioning involved when you generate a generic
function, e.g. a test whether a generic function and/or a default
function already exist or not. In the end I ended up writing a
setGenericS3() method, which does all these checks for you and also
checks some other things. I have been using it for more than one year
now in several different packages and bundles and it seems to work
pretty good. For the source code and for a detailed discussion about
creating generic functions, see
http://www.maths.lth.se/help/R/setGenericS3/. Please feel free to
comment on this and/or to improve the code.

Cheers

Henrik Bengtsson

Centre for Mathematical Sciences
Lund University
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._._._



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._