Skip to content
Prev 180438 / 398506 Next

About the efficiency of R optimization function

popo UBC wrote:
Many functions available in R are implemented using a compiled language such
as C or Fortran- not the R language it's self. For example, the "Source"
section of the help page for optim states that the code for the Nelder-Mead,
BFGS and Conjugate Gradient methods were translated to C from Pascal and
then further optimized. The L-BFGS-B method appears to be implemented as
Fortran code.

Looking at the source of the optim function reveals that results are
computed by a call to .Internal(). Such calls usually indicate that R is
handing computations off to a compiled, rather than interpreted, routine.

If you have C or Fortran code you would prefer to use, take a look at the
help pages for .C() and .Fortran() as well as the "Writing R Extensions"
manual. The command line tool R CMD SHLIB will help you compile your code to
shared libraries that can be loaded by R using dyn.load().

-Charlie




-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University