I have been dipping my toes into Rcpp in order to speed up some of the operations I currently perform in R. A problem I have encountered is when modifying a NumericVector passed by reference to a function.
In particular, the function below does not appear to alter the NumericVector (x)passed to the function:
void f1(NumericVector &x){
NumericVector y(1);
y[0] = 1;
x = y;
}
On the other hand, the code below does:
void f2(NumericVector &x){
NumericVector y(1);
y[0] = 1;
x[0] = y[0];
}
Based on this it seems as if you can't modify a NumericVector passed by reference to a function by assigning another NumericVector to it. Instead you have to modify it element by element. Is this correct?
This isn't necessarily an issue but it seems as if something like the first function should work and so I don't want to loop over each element of the vector unnecessarily.