[R] .Internal(optim)

Duncan Murdoch dmurdoch at pair.com
Wed Jul 9 22:09:24 CEST 2003

On Wed, 9 Jul 2003 15:33:12 -0400, Edoardo Airoldi
<eairoldi at stat.cmu.edu> wrote :

>> hi all,
>>  I am using optim.  I am getting the following error message:
>> Error in optim(par = start.vals[, h], fn = post.func.pois, gr = post.grad.
>> pois,  :
>>         L-BFGS-B needs finite values of fn
>> If I look at optim typing '> optim' it seems that the error comes from 
>> inside .Internal(optim), so I wonder how can I see the code for .Internal(
>> optim)?

Anything that's called by .Internal is C or Fortran code.  You need to
download the R source package, decompress it somewhere, and start
looking around the src directory.

Internal functions are all listed in a big array declared in the
src/main/names.c file.  For example, this line is in that file:

{"optim",	do_optim,	0,	11,	7,	{PP_FUNCALL,
PREC_FN,	0}},

This says that "do_optim" is the function that does all the work.  The
other numbers describe things like how many arguments it takes, how to
deparse it, etc.  You then need to search through all the source to
find do_optim; it's in the file src/main/optim.c.  Reading C code that
works with R objects (declared as SEXP) is not easy, but that's where
you'll need to look.

In the end, I don't think all that work is going to be very fruitful.
You'll just find out that your objective function needs to return
finite values.  You should try to figure out why it doesn't.  Perhaps
if you set the bounds on the region a little smaller you'll fix

Duncan Murdoch

More information about the R-help mailing list