[Rd] a question about optim.R and optim.c in R

Prof J C Nash (U30A) nashjc at uottawa.ca
Tue Jul 8 14:41:38 CEST 2014


As you dig deeper you will find vmmin.c, cgmin.c and (I think) nmmin.c
etc. Those were, as I understand, converted by p2c from my Pascal codes
that you can find in the pascal library on netlib.org. These can be run
with the Free Pascal compiler.

Given how long ago these were developed (>30 years in all cases), they
are due for review. The packages Rvmmin and Rcgmin are all-R
replacements for the 1st two, and nmkb from dfoptim generally offers a
better version of the Nelder-Mead approach. All have bounds-constrained
variants, but for efficiency, there are direct calls of the
unconstrained methods, though I need to provide some nice examples of
when and how to call each. There is likely a place for some compiling of
sections to speed things up, but the R codes are not particularly sluggish.

Side comment: At UseR last week, Yihui Xie sat with me and we
implemented a Fortran language engine for knitr. It looks like a Pascal
one may also be possible, and maybe even a BASIC (though that may need
variants for different platforms). This would allow vignettes to
document some of the legacy code to be written, and that may be an
important matter as the expertise for such older tools moves into
retirement. Off-list communication about such ideas welcome.

John Nash


On 14-07-08 06:00 AM, r-devel-request at r-project.org wrote:
> Message: 2
> Date: Mon, 7 Jul 2014 16:34:59 -0400
> From: Zhiyuan Dong <zhiyuan.dong at gmail.com>
> To: r-devel at r-project.org
> Subject: [Rd] a question about optim.R and optim.c in R
> Message-ID:
> 	<CAN8PBZVW1sd_RQ_qqz3dwbs8r5RwinnNyKm2iaN4O8w4fpGnKQ at mail.gmail.com>
> Content-Type: text/plain
> 
> Hi, I am learning R by reading R source code. Here is one question I have
> about the optim function in R.
> 
> The context : In the optim.R, after all the prep steps, the main function
> call call is made via :
> 
> .External2(C_optim, par, fn1, gr1, method, con, lower, upper).
> 
> So, it seems to me, to follow what is going on from here, that I should
> read the optim function in \src\library\stats\src\optim.c
> 
> where it has this signature :
> 
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
> 
> I am not sure I follow here : In the .External2 call, we have 7 parameters
> :  par, fn1, gr1, method, con, lower, upper; This does not seem to match
> the signature of
> 
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
> 
> However, it seems (from the source code) that the 7 parameters are somehow
> embedded in the 'args' parameter. I am not sure what is going on...Am I
> missing something?
> 
> Thanks much!!!
> 
> Best,
> 
> Zhiyuan
> 
> 	[[alternative HTML version deleted]]



More information about the R-devel mailing list