Skip to content
Prev 246531 / 398502 Next

Converting Fortran or C++ etc to R

Thanks Barry and thanks to others who applied off-list. I can see that I 
should have given more details about my motives for wanting to replace a 
Fortran program by an R one.

At this stage I want to get something working in pure R because it is 
easier to fool around with and tweak with than Fortran and I have a few 
things that I want to try out that will involve perturbing the original 
code and I think I'd rather be doing them in R than in a 3GL.

Now that I have publicly asked the question I find that the answer to it 
occurs to me:

The program that I want to port to R is an ML estimation by the EM 
algorithm. The iterative steps are fairly simple except they need to be 
repeated a large number of times. What I have noticed is that I can 
replace (maybe) the within-step loops by matrix multiplications. This 
means that I will, by using %*%, be effectively handing a lot of the 
work to external Fortran (or similar) routines without calling .Fortran().

OK, I know that you can see though me and I accept that I am just 
rationalising my reluctance to get into package-writing. I will bite the 
bullet on that in due course but for the meantime I'm just going to fool 
around with straight R.

Barry came closest to answering my real question and I will formulate a 
follow-up question as follows:

Does anyone know of a helpful set of examples of the vectorization of code?

Cheers,  Murray
On 6/01/2011 12:32 a.m., Barry Rowlingson wrote: