Enrico,
I was in a similar position with a small likelihood function which was not
vectorizable (is that a word?) and in one morning I had a working function
using Rcpp which was 60 times faster than my reference function in R. I
*strongly* recommend that you use C++ through the Rcpp interface which
really simplifies things, refer to

http://adv-r.had.co.nz/Rcpp.html
http://rcpp.org/

One possible suggestion for a tempate for your function might be found on
http://gallery.rcpp.org/articles/gibbs-sampler/

The Rcpp-devel mailing group is very very helpful and responsive.

Kind regards,
Sean



On 8 July 2014 09:33, Enrico Bibbona <enrico.bibbona@gmail.com> wrote:

> I would like to write a fast version of a function which contains slow
> loops that I cannot vectorize.
> I would like to rewrite it in C, but in the loops I need to call a few
> (two) R functions.
> Which is the best way to do so? I have read that one can call a C library
> which import all the R functions (R.h, is it?). Is that efficient? I tried
> to have a look into the internal C code to find just the two functions I
> need, but it is quite complicated and I did not succeeded.
> Any suggestion?
> Thanks a lot, Enrico Bibbona
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]

