Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Nathan Kurz
On Thu, Feb 26, 2015 at 12:28 PM, Matt D. wrote: > On 2/26/2015 18:59, Dirk Eddelbuettel wrote: >> >> On 26 February 2015 at 18:35, Matt D. wrote: >> | Which incidentally brings me to the advice I usually give in these >> situations: >> | unless you're absolutely dependent on the "features" of >>

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Matt D.
On 2/26/2015 18:59, Dirk Eddelbuettel wrote: On 26 February 2015 at 18:35, Matt D. wrote: | Which incidentally brings me to the advice I usually give in these situations: | unless you're absolutely dependent on the "features" of `Rcpp::NumericVector` | just forget about it and replace all uses wi

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Dirk Eddelbuettel
On 26 February 2015 at 18:35, Matt D. wrote: | Which incidentally brings me to the advice I usually give in these situations: | unless you're absolutely dependent on the "features" of `Rcpp::NumericVector` | just forget about it and replace all uses with the standard container | `std::vector`. No

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Matt D.
On 2/26/2015 16:37, Pierre GLOAGUEN wrote: Thanks, it works! I'm not familiar with C++, is it necessary to always use such a function in C++ or is it because of R/C++ interface? Hi Pierre! You're witnessing yet another fascinating difference between (usual in the world of C++) value semantics

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Pierre GLOAGUEN
Ok, i'll do this. Thanks and have a nice day, Pierre Le 26/02/2015 16:51, Dirk Eddelbuettel a écrit : On 26 February 2015 at 16:37, Pierre GLOAGUEN wrote: | Thanks, it works! | I'm not familiar with C++, is it necessary to always use such a function in C++ | or is it because of R/C++ interface

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Dirk Eddelbuettel
On 26 February 2015 at 16:37, Pierre GLOAGUEN wrote: | Thanks, it works! | I'm not familiar with C++, is it necessary to always use such a function in C++ | or is it because of R/C++ interface? Please use a Google search (or equivalent) for Rcpp::clone. This has been discussed extensively on nu

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Pierre GLOAGUEN
Thanks, it works! I'm not familiar with C++, is it necessary to always use such a function in C++ or is it because of R/C++ interface? Thanks again for your help, Pierre Le 26/02/2015 16:30, Jeffrey Pollock a écrit : Perhaps use the clone() function? library(Rcpp) cppFunction(" NumericVecto

Re: [Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Jeffrey Pollock
Perhaps use the clone() function? library(Rcpp) cppFunction(" NumericVector par_CMAtR(NumericVector vec_CMA) { NumericVector out = clone(vec_CMA); out[5] = exp(out[5]); return out; } ") vec_C <- rep(1, 6) par_CMAtR(vec_C) print(vec_C) On Thu, Feb 26, 2015 at 3:16 PM, Pierre GLOAGUEN

[Rcpp-devel] function modifying it self its argument

2015-02-26 Thread Pierre GLOAGUEN
Hello everybody, I have a very simple example I have a vector vec_CMA which length is a multiple of 6. I want to get the exact same vector, except the last element which is the exponential of the last element of vec_CMA The code is the following //myfun.cpp #include using namespace Rcpp; //