From murdoch at stats.uwo.ca  Sat Jul  5 21:05:21 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sat, 05 Jul 2008 15:05:21 -0400
Subject: [Rd] Editing the "..." argument
In-Reply-To: <486FB57D.6010801@epfl.ch>
References: <486FB57D.6010801@epfl.ch>
Message-ID: <486FC5F1.2020601@stats.uwo.ca>

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



[Rd] Editing the "..." argument
Duncan Murdoch