[Rcpp-devel] redimension help

Dirk Eddelbuettel edd at debian.org
Wed Jun 8 05:36:48 CEST 2011


On 7 June 2011 at 23:18, Silkworth,David J. wrote:
| I have not been slack on reviewing the archives, but they ARE hard to
| search.

A Google query such as

    site:gmane.org gmane.comp.lang.r.rcpp Rcpp::List

is not that hard. YMMV.
 
| So far, I am led to believe that a list of vectors can only be accessed
| during initialization.

Wrong.

| This would seem to be a real problem for entering elements in looped
| increments 10's of thousands of times.
| 
| The original matrix scheme DOES work, but I think I have to improve the
| estimated size of rows, so that I don't create an excessive memory foot
| print.  Once dimensioned a matrix apparently is not going to be resized.
| 
| I am aware that as long as my individual vectors and my matrix row
| lengths are the same size that these will combine into an
| Rcpp::DataFrame.
| 
| Once in R I would have to either find a way to ignore the unfilled
| elements or hopefully the following code would not be too oppressive:
| 
| RcppDF<-RcppDF[1:r,]

What's your obsession with [] ?  They _cannot take multiple arguments_ as
you'd need for i,j coordinates.
 
| I just thought it would be possible to do in C++

Wishing alone does not make it so.  

Dirk
 
 
| 
| 
| 
| Try this:
| 
| require(inline)
| 
| src <- '
|   int s = 7;  // result of original oversize estimate before process
| runs
|   int c = 3;  //known column count established from a list argument
| (variable to function)
|   int r = 4;  // number of rows that more complex process found
| necessary to fill
|   int i = 0;
|   Rcpp::List Lmv(c) ;  // list of matrix column vectors
|   for(  i=0; i<c; i++)  {
|      Rcpp::IntegerVector m(s) ;
|      // insertion of next three lines partially fills the matrix column
| vectors
|      // the same way as previous sample code
|      for( int j=0; j<r; j++){
|        m(j)=  (i+1)*(j+1);
|      }
|      Lmv[i] = m;
|   }
|   // this code does not access the vector elements as I wish
|   for(int j=0; j<c; j++)  {
|      for( i=0; i<r; i++)  {
|         Rcpp::IntegerVector v = Lmv(j);
|         v(i) = (i+1)*(j+1);
|      }
|   }
|   return Lmv;
| '
| 
| fun <- cxxfunction(signature(), src, plugin = "Rcpp")
| print(fun())
| 
| 
| And please do search the list archives. I explained a few times already
| why
| using [][] cannot work.
| 
| 
| 
| Not all STL methods exist in all Rcpp classes.
| 
| Dirk
| 
| 
| 

-- 
Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com


More information about the Rcpp-devel mailing list