<div dir="ltr">Hi all, <div><br></div><div>I am relatively new to Rcpp and a bit confused about the behavior I am seeing from an Rcpp function. It seems that a function created with Rcpp can modify the value of objects in the global environment, yet this behavior depended on the nature of the object. I realize I could code things differently so that the object in the global environment is not affected, but I wanted to make sure there is not something more general I am doing wrong (and which will continue to be wrong without me knowing it!)</div>

<div><br></div><div>Below is a small example where the global value gets altered, followed by an example where it does not. The only difference between them is that in the first (cTest1) the input is NumericVector, while in the second (cTest2) the input is double. </div>

<div><br></div><div><div>### Rcpp function alters values in global environment:</div><div>cppFunction('  </div><div>  double cTest1( NumericVector zzz) {</div><div>    zzz = zzz/10; </div><div>    return 1;</div><div>

   }')</div><div><br></div><div>  zzz=rep(10,3)</div><div>  zzz</div><div>  cTest1(zzz)</div><div>  zzz </div><div><br></div><div>### Rcpp function does not alter values in global environment:</div><div>cppFunction('  </div>

<div>  double cTest2( double zzz) {</div><div>     zzz = zzz/10; </div><div>     return 1;</div><div>   }')</div><div><br></div><div>zzz=10</div><div>cTest2(zzz)</div><div>zzz </div></div><div><div>####################</div>

<div><br></div><div><br></div>Thanks for your help, and sorry for the naive question. </div><div><br></div><div>Nick<br><br>PS - I am running Rcpp 0.10.6, R version 3.0.1</div></div>