[Rcpp-devel] Trailing Index issues, handled as pointer
Mario Deng
mariodeng at googlemail.com
Mon Jul 7 16:33:20 CEST 2014
Hello everyone,
I am trying to implement a data structure using Rcpp. But I am already struggling with my first method.
How things (should) work: I want to my function ("createVectorList") a data frame or matrix. Each column of the matrix gets sorted. This also holds for the rownames - storing the sorted rownames for each sort column gives me big memory footprint, but log(n) access while reading later.
Basically everything is fine, but when accessing some data through a for loop I get "address 0x0, cause 'memory not mapped'".
Here is my Code:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List createVectorList(NumericMatrix df, CharacterVector rownames) {
List sorted_rownames(df.ncol());
for(int i = 0; i < df.ncol(); i++){
NumericVector sorted_vec = df(_,i);
std::sort(sorted_vec.begin(), sorted_vec.end());
NumericVector one_col = df(_,i);
df(_,i)=sorted_vec;
IntegerVector matched = match( sorted_vec, one_col);
CharacterVector one_sorted_row(df.nrow());
for(int j = 0; j < one_sorted_row.length(); j++){
int match_id=matched[j];
String r_name=rownames[match_id];
one_sorted_row[j]=r_name;
}
sorted_rownames[i]=one_sorted_row;
}
return Rcpp::List::create(Rcpp::Named("Matrix") = df, Rcpp::Named("rowIDX")=sorted_rownames);
}
There trouble is within these lines:
for(int j = 0; j < one_sorted_row.length(); j++){
int match_id=matched[j];
String r_name=rownames[match_id];
one_sorted_row[j]=r_name;
}
When executing this, I get the error named above.
What I thought about: rownames should be of the type "Proxy" or so, maybe thats the point?
Maybe one of you has a hint.
With beste regards,
Mario
__
MD
mariodeng at googlemail.com
More information about the Rcpp-devel
mailing list