Give up .C() and switch to .Call() , which allows you to transfer entire R objects as so-called SEXP objects.
You can analyze these difficulties using the C API R or through Rcpp using (which, in our opinion) good higher-level abstractions.
R> library(inline) # use version 0.3.10 for rcpp() wrapper R> R> addMat <- rcpp(signature(ms="numeric"), body=' + Rcpp::NumericMatrix M(ms); + Rcpp::NumericMatrix N = Rcpp::clone(M); + for (int i=0; i<M.nrow(); i++) + for (int j=0; j<M.ncol(); j++) + N(i,j) = M(i,j) + 1; + return(N); + ') R> addMat(matrix(1:9,3,3)) [,1] [,2] [,3] [1,] 2 5 8 [2,] 3 6 9 [3,] 4 7 10 R>
source share