I have written some code for doing mathematical optimization in
R.

tests.zip, some tests for comparing different BFGS
implementations. The script compares three implementations: my own (see
below), GSL's, and R's.

bfgs.zip, an implemention of the
Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm for smooth function
minimization. It supports box constraints, and uses the More-Thuente
linesearch algorithm. I like to think the code is easy to understand and play
with, partly because it is written in R. I think the linesearch algorithm
needs some work -- it could make much better use of derivative information.

multimin.zip, an R wrapper for the GNU Scientific
Library's function optimization code.
Included in the
R gsl package.