[Rd] a question about optim.R and optim.c in R
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-requ...@r-project.org wrote: Message: 2 Date: Mon, 7 Jul 2014 16:34:59 -0400 From: Zhiyuan Dong zhiyuan.d...@gmail.com To: r-devel@r-project.org Subject: [Rd] a question about optim.R and optim.c in R Message-ID: can8pbzvw1sd_rq_qqz3dwbs8r5rwinnnykm2ian4o8w4fpg...@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]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] a question about optim.R and optim.c in R
Hi, On Mon, Jul 7, 2014 at 4:34 PM, Zhiyuan Dong zhiyuan.d...@gmail.com wrote: Hi, I am learning R by reading R source code. That's very brave of you. You might also try reading some of the documentation and contributed documentation, like: http://adv-r.had.co.nz/C-interface.html and http://cran.r-project.org/doc/manuals/r-devel/R-exts.html Sarah 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 -- Sarah Goslee http://www.functionaldiversity.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] a question about optim.R and optim.c in R
On Jul 7, 2014, at 4:34 PM, Zhiyuan Dong zhiyuan.d...@gmail.com wrote: 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? IIRC, args is a pairlist object. If the analogy helps, it's something like the OO pattern of sticking all your function parameters in an argument and passing that instead of passing them all as formals. One advantage of this is sane(er) handling of variadic functions at the C level. Michael Thanks much!!! Best, Zhiyuan [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel