[R] Calling R from external code?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 23 10:10:19 CET 2001


On Mon, 22 Jan 2001, Yves Gauvreau wrote:

> Hi every one,
>
> I'm thinking of using some optimization algorithm in conjunction with R
> 1.2.[01]. I assume that it is usual for this kind of code be given a pointer
> to the function to be optimize and a bunch of parameters for both the
> algorithm and for the function. In order to be flexible the ideal would be
> to be able to write the function to be optimize as a R function. But...
>
> I got myself a copy of "S programming" (I got it from Amazon while it was at
> ~ $17.98) and I read chapter 6 (6.3). I also read "Writing R extensions".
> >From what I've read the authors basically suggest to forget that and the
> main reason they give is that the process can be "extremely slow".

You missed the point (p. 139): use the methods in section 6.4 these days.
They have a much smaller penalty.  You will need to supplement that by
`Writing R extensions' as the R internals have changed a bit.

> I even
> took a look at optim.c which does exactly what I would like to be able to do
> for this algorithm. I also got my hand on the Fortran code for L-BFGS-B from
> R. H. Byrd, P. Lu, J. Nocedal and C. Zhu (NETLIB) and they also have the
> same example program as R (the extended Rosenbrock function). As expected
> the Fortran program is a lot faster.

That is an extreme example (a trivial function, so the calling overhead
is large in comparison to everything else).

> The functions I would like to optimize will probably be a lot of work for
> both the algorithm and within the functions themselves. So this is kind of a
> dilemma.
>
> Is the only alternative to this situation is writing the function to be
> optimized as external code and setting up things such that the process can
> be initiated from an R function?

The optim approach (effectively that used by .Call) is likely to be pretty
efficient.  call_R is hard to use and now deprecated.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list