[Rcpp-devel] Calling RInside constructor multiple times

Dirk Eddelbuettel edd at debian.org
Fri Jun 11 16:20:22 CEST 2010


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.

-- 
  Regards, Dirk


More information about the Rcpp-devel mailing list