[R] Rcpp, function signature

Michael Meyer spyqqqdia at yahoo.com
Thu Aug 27 12:37:15 CEST 2015


Greetings,

I am an  (very) grateful user of Rcpp.
As such I defined a function 

// [[Rcpp::export]]
NumericVector
leftShift(NumericVector x){

  for(int i=0;i<n-1;i++) x[i]=x[i+1];
  return x;
}

expecting this function not to affect the parameter x outside
the function body as it is passed in by value.

However subsequent tests showed that it does affect x.
What is going on here?
Is sourceCpp rewriting this code in somne fashion??

Michael Meyer



More information about the R-help mailing list