[Rcpp-devel] Accessing/Copying rows/columns of matrices

Michael Braun braunm at MIT.EDU
Thu Mar 24 22:45:12 CET 2011


Hi, all.  Another question as I embark on my first project that uses Rcpp.

Consider the following test code, that comes right off of the Using Matrices section of the Rcpp-quickref file on CRAN.

RcppExport int test() {

  Rcpp::NumericMatrix xx(3,2);
  int i;
  int xsize = xx.nrow() * xx.ncol();

  for (i = 0; i < xsize; i++) {
    xx[i] = 7;
  }

  Rcpp::NumericMatrix::Column z1 = xx( _,1);   // line 91
//  Rcpp::NumericVector z2 = xx(_,1); 

  return 0;

}


When I try to compile this code in g++, I get the following:

g++ -O0 -arch x86_64 -g -Wall -fopenmp -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64  -I/usr/local/include -I/Library/Frameworks/R.framework/Resources/library/Rcpp/include -c Rcpp_omp.cpp -o Rcpp_omp.o
Rcpp_omp.cpp: In function ‘int test()’:
Rcpp_omp.cpp:91: error: ‘_’ was not declared in this scope
Rcpp_omp.cpp:91: warning: unused variable ‘z1’

and I get something similar if I comment out the z1 assignment instead of z2.  I tried playing around with spacing around the underscore, to no avail.  This also happens with the Intel compiler, so I doubt it's that.



More information about the Rcpp-devel mailing list