Use User Defined R Function in C

I am trying to extend an R package that is written entirely in C. I have the following problem: in the C code, I want to make a call to a user-defined R function, as an optimization routine does. However, when I try to track the main steps in optimization, I am (more or less) able to follow the steps in the C source code, but once I try to understand how a call from R is optimized (via .External2) I can't even figure out. what is the relationship between the arguments passed through .External2 for optimization. In particular, in src/library/stats/src/optim.c

we have the following

SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)

      

and in src/library/stats/R/optim.R

we have what (what I suppose to be) optim is called this way

.External2(C_optim, par, fn1, gr1, method, con, lower, upper)

      

How are call, op, args and rho arguments passed for optimization with .External2?

A few years ago I read about the R_call function or something like that to call R functions in C. I remember that even at that time this function was deprecated, but it just has to figure out what I need.

+3


source to share





All Articles