[Rd] The best way to use R's linear algebra functions from C

From: Daniel Oberski <daniel.oberski_at_gmail.com>
Date: Sat, 12 May 2007 20:48:20 +0200

First of all, thanks to everybody for R.

I have written a program in C that requires some basic matrix operations, namely the following:

Since I am a happy R user I thought I could call R from within my program for this purpose. I read "Writing R Extensions" and "R Internals" and a bunch of other things from the web, ran the "Embedded" tests, and grep'ed / looked at the source code.

It is now my understanding that there are several ways I could use R from C:

  1. Pass data from C to an R function, loaded during R runtime;
  2. Build R statements and use Rparse.h to execute them;
  3. Use Rembedded.h to call R's C functions;
  4. Directly call R's C functions.
  5. would be the fastest (I think?), and speed is some concern. However, I am finding it very tough going to discover how to implement this. For example: given two matrices represented as arrays of doubles and their numbers of rows and columns in C, which function in the R code should I call to multiply them (matprod and co. are not exported)? Which headers should I include? Should I link against a library, and if so, which one?

Currently I am leaning towards a very roundabout solution: copy the double arrays into SEXPs, use Rembedded.h and load the required formulas from a .R file. This solution seems rather hacky and slow to me, but it is the only one I can get to work right now. However, I would rather not use it.

In short, my question is: what is the proper or preferred method of solving this problem, and how do I find out how to apply it?

Thank you very much for your attention.

Best regards,

Daniel Oberski
University of Tilburg / European Social Survey


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 12 May 2007 - 18:51:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 May 2007 - 19:33:55 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.