R is already initialized using pointer of Rinside object
zhaofeng-shu33 opened this issue · 3 comments
I compile the following simple code in debian buster by
g++ -I/usr/lib/R/site-library/Rcpp/include -I/usr/lib/R/site-library/RInside/include -I/usr/share/R/include/ -L/usr/lib/R/site-library/Rcpp/libs/ -L/usr/lib/R/site-library/RInside/lib/ -lR -lRInside -l:Rcpp.so main01.cpp -o main01
#include <RInside.h>
int main() {
RInside* rinside;
rinside = new RInside();
delete rinside;
rinside = new RInside();
delete rinside;
}
When I run the program, I get the console message "R is already initialized". I do not know which is wrong with my code.
This is documented (somewhere ...). You can only have one instance of RInside
(per process, a constraint that comes down from how R is designed and set up) so your code is in fact wrong. And yes, you do call delete but R (and that is documented somewhere in their internals) does not do a perfect wind-down to be callable again). It is your responsilibility to create one RInside
object and to hang on to it.
Thanks for your suggestions.
RInside
isn't exactly a brand new project so some of these things have come up before, but these days it's no longer as obvious where that was. I once tried what you tried to, and I think I documented it as a consequence but if you found it lacking ... well sorry. Suggestions welcome -- there are still several dozen examples in the package as is.