[Rcpp-devel] Calling RInside constructor multiple times

Romain Francois romain at r-enthusiasts.com
Mon Jun 14 12:08:33 CEST 2010


Hello,

We cannot load more than one R interpreter per thread.

Until now, we rely on users not to di it, but it might be worth adding 
this constraint (which is imposed by R) into the design of RInside, i.e. 
we would implement the singleton pattern.

When you are done with temp_1.Rdata, can't you just clear things and 
load temp_2.Rdata.

Romain


Le 11/06/10 16:20, Dirk Eddelbuettel a écrit :
>
>
> Hi Peter,
>
> Thanks for your interest in in RInside!
>
> On 11 June 2010 at 09:53, Peter Holt wrote:
> | Hello List,
> |
> | I wrote a C++ program that does the following:
> |
> | **************************************************************
> |
> | int main (int argc, char **argv)
> | {
> |    RInside* temp_1 = new RInside (argc, argv)
> |
> |    // use temp_1 to load "temp_1.RData", and invoke
> |    // functions that are defined within "temp_1.RData"
> |
> |    ......
> |
> |    // Delete the created RInside instance
> |
> |    delete temp1;
> |
> |   // create another RInside instance, as we now would
> |   // like to load "temp_2.RData" and invoke functions
> |   // defined within "temp_2.RData"
> |
> |   RInside* temp_2 = new RInside (argc, argv)
> |
> |    // use temp_2 to invoke operations within "temp_2.RData"
> |
> |    ....
> |
> |    // Delete the created RInside instance
> |
> |    delete temp_2;
> | }
> |
> | *********************************************************************
> |
> | The above described program crashes when we try to create the "temp_2" RInside
> | object, and gives the following error:
> |
> | Error in .Call("R_isMethodsDispatchOn", onOff, PACKAGE = "base") :
> |   Incorrect number of arguments (2), expecting 1 for R_isMethodsDispatchOn
> |
> | Can you please let me know what should I do to properly delete the "temp_1"
> | RInside object, so that I could create "temp_2" RInside object and proceed with
> | my program?
>
> It isn't really meant to be used like that: One RInside instance per
> program. R is after all single-threaded. If you must, you can have one per
> thread as in the MPI examples.
>
> If you need a second dataset, can't you just load it?
>
> If the delete doesn't do sufficient cleanup, and you really need to, or want
> to, retain the design above ... then you'd have to help debug the ctor / dtor
> pairing.
>
> Lastly, the usual complaint: Your example is not replicable as we do not have
> your RData files, and the code in insufficient to show how you replace one of
> the automagically loaded files with the other.
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5



More information about the Rcpp-devel mailing list