[Rd] array indexes in C

From: Benjamin Tyner <btyner_at_stat.purdue.edu>
Date: Sun 19 Nov 2006 - 14:55:17 GMT


Tamas,

You could write convenience functions, but I have used the C99 mechanism for variable length arrays with no problems calling from R. One thing you have to keep in mind though is that (as far as I know) the dimensions must be passed before the array reference. So for example,

r <- .C("foo",

              as.integer(ni),
              as.integer(nj),
              x = double(ni * nj),
              ...)

with your function defined as

void foo(int *ni, int *nj, double x[*ni][*nj]) {
...

Then in C you can access elements of x via x[3][4], for example.

Ben



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Nov 20 01:58:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 19 Nov 2006 - 15:30:41 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.