[R] C++ and R interface

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Nov 6 17:19:14 CET 2007


On Tue, 6 Nov 2007, Deepankar Basu wrote:

> Hi All,
>
> I am trying to do an ML estimation in R. My likelihood function has
> several nested loops and so it takes a lot of time (days when I use the
> genetic algorithm for optimization) for the optimization to finish.
> Unable to avoid loops, I am thinking of writing the likelihood function
> in C++ and calling it from within R when using *optim()*. I found that
> one can call C functions (once they have been compiled) from within R
> with
>
>> dyn.load("file.so")
>
> and
>
>> .C("function", ...)
>
> Can the same be done for C++ code?

Yes, and the manual about C ('Writing R Extensions') discusses C++ as well.

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list