From sarah.goslee at gmail.com  Mon Jul  7 23:20:54 2014
From: sarah.goslee at gmail.com (Sarah Goslee)
Date: Mon, 7 Jul 2014 17:20:54 -0400
Subject: [Rd] a question about optim.R and optim.c in R
In-Reply-To: <CAN8PBZVW1sd_RQ_qqz3dwbs8r5RwinnNyKm2iaN4O8w4fpGnKQ@mail.gmail.com>
References: <CAN8PBZVW1sd_RQ_qqz3dwbs8r5RwinnNyKm2iaN4O8w4fpGnKQ@mail.gmail.com>
Message-ID: <CAM_vju=JTeyPXq=mYNd2rV6Hk9Zk9qGYyQSiv5rCGqKfb-iHgQ@mail.gmail.com>

Hi,

On Mon, Jul 7, 2014 at 4:34 PM, Zhiyuan Dong <zhiyuan.dong at 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



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