astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
103 stars 36 forks source link

ignore `...` when checking argument lists in .checkfunargs ? #164

Closed bbolker closed 6 days ago

bbolker commented 6 days ago
library('nloptr')
## Rosenbrock Banana function and gradient in separate functions
eval_f <- function(x) {
       return(100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2)
}
eval_f2 <- function(x, ...) {
       return(100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2)
}
nloptr(x0 = c(-1.2, 1), eval_f = eval_f, opts = list("algorithm"="NLOPT_LN_BOBYQA"))
nloptr(x0 = c(-1.2, 1), eval_f = eval_f2, opts = list("algorithm"="NLOPT_LN_BOBYQA"))

Error in .checkfunargs(eval_f, arglist, "eval_f") : eval_f requires argument '...' but this has not been passed to the 'nloptr' function.

It would be super-convenient if .checkfunargs could be lenient about ..., as this would make it much easier to use nloptr with objective functions constructed by the TMB package.

I'm guessing this would be easy and am happy to submit a PR if it seems like a worthy idea.

bbolker commented 6 days ago

Oops! already underway in https://github.com/astamm/nloptr/pull/102, I will comment there instead.