Yes, I think for all practical purposes it (usually?) is. Here's an example. Suppose I wish to change the default "constant" argument of mad from 1.48 to 2. Then> z<-formals(mad) > z$constant<-2 > mad<-as.function(c(z,body(mad))) > madfunction (x, center = median(x), constant = 2, na.rm = FALSE, low = FALSE, high = FALSE) { if (na.rm) x <- x[!is.na(x)] n <- length(x) constant * if ((low || high) && n%%2 == 0) { if (low && high) stop("`low' and `high' can't be both TRUE") n2 <- n%/%2 + as.integer(high) sort(abs(x - center), partial = n2)[n2] } else median(abs(x - center)) } If you now attach the workspace/environment containing this newly defined mad function to the search list before the stats package (which contains the original mad()) you have effectively changed the default argument without changing the function. I hope experts will let us know when this can't be done (perhaps with .internal functions or non-exported functions in namespaces, though it isn't clear to me that one couldn't manually export them and do this here, too). Of course, all the usual warnings about masking existing functions apply. Cheers, -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of RenE > J.V. Bertin > Sent: Wednesday, November 17, 2004 4:05 PM > To: p.connolly at hortresearch.co.nz > Cc: r-help at r-project.org; r-devel at r-project.org > Subject: Re: [R] changing (core) function argument defaults? > > >From: Patrick Connolly <p.connolly at hortresearch.co.nz> > >To: "RenE J.V. Bertin" <rjvbertin at hotmail.com> > >Subject: Re: [R] changing (core) function argument defaults? > >Date: Thu, 18 Nov 2004 11:43:10 +1300 > > > > >On Wed, 20-Oct-2004 at 07:48PM +0200, RenE J.V. Bertin wrote: > > > >|> Hello, > >|> > > > >|> Is it possible to change the defaults for the arguments to a > >|> function, without changing the function code > itself? I'm asking > >|> because I'd like to override the default dimensions > and font > family > >|> for a graphics device. Before 2.0.0, I'd just do > that with a small > >|> edit in the appropriate .R file containing the > device function > >|> definition. I appears to be possible no longer. So > rather than > >|> copying the definition into my own .Rprofile, it > would be nice if > >|> just the defaults could be modified... > > > >I didn't notice a response to this question. I'd like to > do something > >similar and haven't been able to work out how to do it. > > > > > >best > > > >-- > >Patrick Connolly > >HortResearch > >Mt Albert > >Auckland > >New Zealand > >Ph: +64-9 815 4200 x 7188 > > No, I haven't noticed a reply to this question neither. > > Best, > Ren?? Bertin > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
RenE J.V. Bertin
2004-Nov-18 01:05 UTC
[Rd] Re: [R] changing (core) function argument defaults?
>From: Patrick Connolly <p.connolly@hortresearch.co.nz> >To: "RenE J.V. Bertin" <rjvbertin@hotmail.com> >Subject: Re: [R] changing (core) function argument defaults? >Date: Thu, 18 Nov 2004 11:43:10 +1300 > >On Wed, 20-Oct-2004 at 07:48PM +0200, RenE J.V. Bertin wrote: > >|> Hello, >|> > >|> Is it possible to change the defaults for the arguments to a >|> function, without changing the function code itself? I'm asking >|> because I'd like to override the default dimensions and font family >|> for a graphics device. Before 2.0.0, I'd just do that with a small >|> edit in the appropriate .R file containing the device function >|> definition. I appears to be possible no longer. So rather than >|> copying the definition into my own .Rprofile, it would be nice if >|> just the defaults could be modified... > >I didn't notice a response to this question. I'd like to do something >similar and haven't been able to work out how to do it. > > >best > >-- >Patrick Connolly >HortResearch >Mt Albert >Auckland >New Zealand >Ph: +64-9 815 4200 x 7188 No, I haven't noticed a reply to this question neither. Best, René Bertin
Thomas Lumley
2004-Nov-18 01:18 UTC
[Rd] Re: [R] changing (core) function argument defaults?
Restricted to r-devel (it is almost never appropriate to send the same message to both lists). On Thu, 18 Nov 2004, RenE J.V. Bertin wrote:> >From: Patrick Connolly <p.connolly@hortresearch.co.nz> > >To: "RenE J.V. Bertin" <rjvbertin@hotmail.com> > >Subject: Re: [R] changing (core) function argument defaults? > >Date: Thu, 18 Nov 2004 11:43:10 +1300 > > > > >On Wed, 20-Oct-2004 at 07:48PM +0200, RenE J.V. Bertin wrote: > > > >|> Hello, > >|> > > > >|> Is it possible to change the defaults for the arguments to a > >|> function, without changing the function code itself? I'm asking > >|> because I'd like to override the default dimensions and font family > >|> for a graphics device. Before 2.0.0, I'd just do that with a small > >|> edit in the appropriate .R file containing the device function > >|> definition. I appears to be possible no longer. So rather than > >|> copying the definition into my own .Rprofile, it would be nice if > >|> just the defaults could be modified... > > > >I didn't notice a response to this question. I'd like to do something > >similar and haven't been able to work out how to do it.You can write a wrapper X11<-function(display="",width=2,height=2,...){ grDevices::X11(display,width,height,...) } and put that into your Rprofile. -thomas
RenE J.V. Bertin
2004-Nov-18 01:46 UTC
[Rd] Re: [R] changing (core) function argument defaults?
>Restricted to r-devel (it is almost never appropriate to send the >same message to both lists). Fine with me! >X11<-function(display="",width=2,height=2,...){ > grDevices::X11(display,width,height,...) >} > >and put that into your Rprofile. Great, thanks! Is there documentation from which to find out what to put in that wrapper function, for an arbitrary function? René Bertin
Spencer Graves
2004-Nov-18 01:47 UTC
[Rd] Re: [R] Changing graphics defaults [was: changing (core) function argument defaults?]
Under the S3 standard, you could make a local copy of any function and change the defaults in that local copy. That may not always work under the S4 standard methods dispatch going to code hidden in namespaces. In any event, it should be easy (and safer) to write a function with a slightly different name, e.g., adding a dot "." to the end of the name, that would have different defaults and would do nothing but call the function of interest. This might be safer I don't have any suggestions about changing graphics defaults other than to ask for that specifically -- e.g., by changing the subject line to this email. hope this helps. spencer graves RenE J.V. Bertin wrote:> >From: Patrick Connolly <p.connolly@hortresearch.co.nz> > >To: "RenE J.V. Bertin" <rjvbertin@hotmail.com> > >Subject: Re: [R] changing (core) function argument defaults? > >Date: Thu, 18 Nov 2004 11:43:10 +1300 > > > > >On Wed, 20-Oct-2004 at 07:48PM +0200, RenE J.V. Bertin wrote: > > > >|> Hello, > >|> > > > >|> Is it possible to change the defaults for the arguments to a > >|> function, without changing the function code itself? I'm > asking > >|> because I'd like to override the default dimensions and font > family > >|> for a graphics device. Before 2.0.0, I'd just do that with a > small > >|> edit in the appropriate .R file containing the device function > >|> definition. I appears to be possible no longer. So rather than > >|> copying the definition into my own .Rprofile, it would be > nice if > >|> just the defaults could be modified... > > > >I didn't notice a response to this question. I'd like to do > something > >similar and haven't been able to work out how to do it. > > > > > >best > > > >-- > >Patrick Connolly > >HortResearch > >Mt Albert > >Auckland > >New Zealand > >Ph: +64-9 815 4200 x 7188 > > No, I haven't noticed a reply to this question neither. > > Best, > Ren? Bertin > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html-- Spencer Graves, PhD, Senior Development Engineer O: (408)938-4420; mobile: (408)655-4567