[Rcpp-devel] Keep variables in C++ environment

Romain Francois francoisromain at free.fr
Wed Jan 27 17:35:36 CET 2010


On 01/27/2010 05:29 PM, Mattias Nyström wrote:
> Hi,
>
> I'm using the Rcpp package to do some operations in C++. For example reading large files and do some calculations. I call the C++ function several times, so I would like the C++ environment keep the objects and variables in the memory when I'm going back to R. So my question; is it possible to set variables, read in files, etc. in C++ and keep them in the memory until I call the function next time?

With the new api, i.e. the classes in the Rcpp namespace it is 
definitely possible. This was one of the goals.

So if you do something like this :

Rcpp::CharacterVector x(2) ;
x[0] = "foo" ;
x[1] = "bar" ;

You can then put x wherever you like and use it when you come back.

With the classic api, it is not possible I think. Dirk might prove me wrong.

> Another question, is this the right mailing list for how-to-use-Rcpp-questions, or is it only for the developing of Rcpp?

That's the right list.

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009



More information about the Rcpp-devel mailing list