Re: [Rcpp-devel] function created from cxxfunction modifies input?

2012-07-07 Thread Dirk Eddelbuettel
Hi Josh, On 7 July 2012 at 17:05, Joshua Wiley wrote: | Thank you so much! That worked and helped me understand why it was | happening :) The idea of pointers is new to me so I think I need to | spend more time learning about that. You can think of the Rcpp::* objects as 'proxies' for the R ob

Re: [Rcpp-devel] function created from cxxfunction modifies input?

2012-07-07 Thread Dirk Eddelbuettel
On 8 July 2012 at 01:46, Alexandre Bujard wrote: | Hi Joshua, | | When you declare "NumericVector xx(x)" xx is a copy of the pointer x. But they | both address the same location in the memory. +1 | What you need here is to do a "deep copy" of the vector x. The best was to do | that in Rcpp is t

Re: [Rcpp-devel] function created from cxxfunction modifies input?

2012-07-07 Thread Joshua Wiley
Hi Alexandre, Thank you so much! That worked and helped me understand why it was happening :) The idea of pointers is new to me so I think I need to spend more time learning about that. Thanks again, Josh On Sat, Jul 7, 2012 at 4:46 PM, Alexandre Bujard wrote: > Hi Joshua, > > When you decl

Re: [Rcpp-devel] function created from cxxfunction modifies input?

2012-07-07 Thread Alexandre Bujard
Hi Joshua, When you declare "NumericVector xx(x)" xx is a copy of the pointer x. But they both address the same location in the memory. What you need here is to do a "deep copy" of the vector x. The best was to do that in Rcpp is to use the function "clone". Also declaring your vector xx with "con

[Rcpp-devel] function created from cxxfunction modifies input?

2012-07-07 Thread Joshua Wiley
Hi, I am familiar with R but quite new to C++. I am reading a C++ textbook, so if this is an obvious question just resulting in my ignorance of C++, please let me know. I tried to translate someone else's R loop that was slow into c++ to use with Rcpp and the inline package: require(Rcpp) requi