[Rd] nlm and optional arguments

Ben Bolker bolker@zoo.ufl.edu
Mon, 6 Mar 2000 16:55:12 -0500 (EST)


  It would be really nice if nlm took a set of "..." optional arguments
that were passed through to the objective function.  This level of hacking
is probably slightly beyond me: is there a reason it would be technically
difficult/inefficient?  (I have a vague memory that it used to work this
way either in S-PLUS or in some previous version of R, but I could easily
be wrong.)

  Here's a hack in R code that works for me (basically copying the R code
of nlm() but defining a temporary function that passes the optional
arguments to the objective function), but I presume this would be cleaner
and faster if implemented at a lower level ...

nlm2 <- function(f, p, hessian=FALSE, typsize=rep(1,length(p)),
                fscale=1, print.level=0, ndigit=12, gradtol=1e-6,
                stepmax=max(1000 * sqrt(sum((p/typsize)^2)), 1000),
                steptol=1e-6, iterlim=100, check.analyticals=TRUE, ...) {
  tmpf <- function(x) {
    f(x,...)
  }
  nlm(tmpf,p,hessian=hessian,typsize=typsize,fscale=fscale,print.level=print.level,
      ndigit=ndigit,gradtol=gradtol,stepmax=stepmax,steptol=steptol,iterlim=iterlim,
      check.analyticals=check.analyticals)
}

  As a matter of general principle, would the R-core folks prefer that
"wishlist" items like this get sent to R-bugs (so they can be kept better
track of) or not (so they don't clutter up the bugs database) ?

-- 
Ben Bolker                                  bolker@zoo.ufl.edu
Zoology Department, University of Florida   http://www.zoo.ufl.edu/bolker
318 Carr Hall/Box 118525                    tel: (352) 392-5697
Gainesville, FL 32611-8525                  fax: (352) 392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._