[Rcpp-devel] accessing list elements without using names

Sameer Soi sameersoi at gmail.com
Fri Feb 10 20:49:33 CET 2012

Hello Rcpp'ers,

I want to access a List of matrices in an Rcpp/C++ function that will
passed to me via R...

src <- "
  using namespace Rcpp ;
  List inputList(L) ;
  NumericMatrix tmpMatrix ;

  tmpMatrix = NumericMatrix(inputList[0]) ;
  return(wrap(tmpMatrix.ncol())) ;
test <- cxxfunction(signature(L="list"), src, plugin = "Rcpp" )

This gives me the following error-

file30b9664194fc.cpp: In function ‘SEXPREC* file30b9664194fc(SEXPREC*)’:
file30b9664194fc.cpp:34: error: call of overloaded
‘Matrix(Rcpp::internal::generic_proxy<19>)’ is ambiguous
/usr/share/R/include/Rcpp/vector/SubMatrix.h:57: note: candidates are:
Rcpp::Matrix<RTYPE>::Matrix(const Rcpp::SubMatrix<RTYPE>&) [with int RTYPE
= 14]
/usr/share/R/include/Rcpp/vector/Matrix.h:67: note:
Rcpp::Matrix<RTYPE>::Matrix(const Rcpp::Matrix<RTYPE>&) [with int RTYPE =
/usr/share/R/include/Rcpp/vector/Matrix.h:65: note:
Rcpp::Matrix<RTYPE>::Matrix(const int&) [with int RTYPE = 14]
/usr/share/R/include/Rcpp/vector/Matrix.h:46: note:
Rcpp::Matrix<RTYPE>::Matrix(const Rcpp::Dimension&) [with int RTYPE = 14]
/usr/share/R/include/Rcpp/vector/Matrix.h:39: note:
Rcpp::Matrix<RTYPE>::Matrix(SEXPREC*) [with int RTYPE = 14]
make: *** [file30b9664194fc.o] Error 1

In looking at the error, it's not clear to me how these candidates will
help. What am I missing in telling Rcpp what class of object it should be
expecting coming out of inputList?

I know this kind of question (i.e. I want a 3d cube etc) pops up frequently
and the answer is typically "use arma's 3d cubes" (e.g.
but I don't intend on doing linear algebra. My data really is just a series
of matrices of arbitrary sizes.

Also, I looked into multi-dimensional arrays, but how to access them seems
unclear; I did see a post on this list to that nature but the solution
seemed inelegant.

Thanks in advance for any help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120210/45d73ede/attachment.html>

More information about the Rcpp-devel mailing list