[Rd] Editing the "..." argument

Duncan Murdoch murdoch at stats.uwo.ca
Sat Jul 5 21:05:21 CEST 2008


On 05/07/2008 1:55 PM, Mathieu Ribatet wrote:
>     Dear all,
> 
> I'd like tweaking the ... arguments that one user can pass in my 
> function for fitting a model. More precisely, my objective function is 
> (really) problematic to optimize using the "optim" function. 
> Consequently, I'd like to add in the "control" argument of the latter 
> function a "ndeps = rep(something, #par)" and/or "parscale = something" 
> if the user has not specified it already.
> 
> Do you know a way to deal with this point?
> In advance, thanks.

It's generally not necessary to edit the ... args, but one way to do it 
is like this:

   dots <- list(...)
   # do some editing
   # instead of optim(a, b, ...), now you do
   do.call(optim, c(list(a, b), dots))

In the particular example you gave, I wouldn't do this; I'd give control 
as an arg to your function, and just edit that.  For example,

myoptim <- function(control = list(), ...) {
   if (is.null(control$ndeps)) control$ndeps <- rep(something, par)
   if (is.null(control$parscale)) control$parscale <- something
   optim(control=control, ...)
}

Duncan Murdoch



More information about the R-devel mailing list