This may be a very basic request, but I have a Rcpp function in R that calculates various matrices which I want to pass back to R. My code looks like this:
zeromatrix <- matrix(0,6,1)
east <- matrix(seq(1:48),6,8)
west <- matrix(seq(1:48),6,8)
func <- 'NumericMatrix eastC(NumericMatrix e, NumericMatrix w, NumericMatrix zeromatrix) {
int ecoln=e.ncol();
int ecolnlessone = ecoln - 1;
NumericMatrix eout(e.nrow(),e.ncol()) ;
for (int j = 0;j < ecoln;j++) {
if (j > 0) {
eout(_,j) = e(_,j-1);
} else {
eout(_,j) = e(_,0);
}
}
eout(_,0) = zeromatrix(_,0);
return eout;
NumericMatrix wout(w.nrow(),w.ncol()) ;
for (int j = 0;j < ecoln;j++) {
if (j < ecolnlessone) {
wout(_,j) = w(_,j+1);
} else {
wout(_,j) = w(_,j);
}
}
wout(_,ecolnlessone) = zeromatrix(_,0);
return wout;
}'
cppFunction(func)
d <- eastC(east, west, zeromatrix)
I want both 'eout' and 'wout' to be passed back to R but obviously only the last returned value is passed back (i.e. wout). So d becomes wout. How do I extract multiple objects (i.e. eout and wout in this case)? I did see in Dirk's introduction sheets to Rcpp and it had something about list(ret) but when I tried this my code wouldn't compile. Any help would be hugely appreciated?