Dear R devel,
Apologies for these (most probably trivial) questions, doing my first
attempt to call C from R (and actually learning C in the process).
I need to pass a matrix to C, and after reading R-exts.pdf (many
times), I was unable to find how to handle matrices at C-level...
except for, what probably is the answer, that matrices are in fact
vectors with dimensions.
This is a sample code I am using at C level:
????????????????????????
# include <R.h>
# include <Rinternals.h>
# include <R_ext/Rdynload.h>
SEXP foo(SEXP x) {
SEXP dimx;
double *px, *pdimx;
PROTECT(dimx = getAttrib(x, R_DimSymbol));
px = REAL(x);
UNPROTECT(1);
return(dimx);
}
????????????????????????
The question is: how to create pointers to dimx (in order to extract
individual values)?
I tried:
pdimx = REAL(dimx);
This is where R complains that:
REAL() can only be applied to a 'numeric', not a 'integer'