[Rcpp-devel] RInside destructor not working properly?

Christian Sigg christian at sigg-iten.ch
Mon Aug 27 14:44:10 CEST 2012


Dear Dirk

Thank you for the reply (and for Rcpp and RInside).

> | Question: Is the RInside destructor not working properly? I would have expected that both in foo() and bar(), an instance of R is created and then destroyed| immediately, without producing any kind of output.
> 
> No, wrong setup. R is single-threaded, and you can have only
> precisely __ONE__ instance of R in your program. You have two.

I was not aware that two instances of R are active at the same time. It was my expectation that by instantiating the RInside class as a local variable, at the end of foo() the destructor R.~RInside() would be called and the encapsulated R instance would be terminated, before a new one is instantiated in bar(). 

I did take a cursory glance at the implementation of ~RInside() before asking the question, and the function call

Rf_endEmbeddedR(0);

gave me that (wrong) impression. I don't know the R implementation internals.

> Create one in main() and pass references around.


Is it possible to terminate the RInside instance instead, and later start a new one? I don't think that it is proper to modify main() with the unit testing framework that I'm using (gtest), as the tests are discovered without explicitly calling them from main().

Regards
Christian


More information about the Rcpp-devel mailing list