Re: [Rd] Terminating and restarting an embedded R instance possible?

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Thu, 30 Aug 2012 11:14:59 -0400

On Aug 29, 2012, at 10:08 AM, Christian Sigg <christian_at_sigg-iten.ch> wrote:

> I am developing R functions that interface with C++ code from the OpenCV library. During development and unit testing, I embed an R instance to prepare the environment in which the function encapsulating OpenCV code is called.
>
> Running the unit testing suite results in starting (and later terminating) an embedded R instance for each test. This produces a series of error messages when Rf_initEmbeddedR is called for the second time.

To my best knowledge you cannot init R more than once in the same process. There are many global variables that rely on being initialized by the data segment. Supporting re-init of R would be a considerable effort as many of those are static so there is no simple way to re-set them.

Cheers,
Simon

> This error is reproduced by running
>
> #include <Rembedded.h>
>
> int main(int argc, char **argv) {
>
> Rf_initEmbeddedR(argc, argv);
> Rf_endEmbeddedR(0);
>
> Rf_initEmbeddedR(argc, argv);
> Rf_endEmbeddedR(0);
>
> return 0;
> }
>
> which outputs the following two lines
>
> Error: bad target context--should NEVER happen;
> please bug.report() [R_run_onexits]
>
> a great number of times (this is on OS X 10.7 with Xcode 4.4.1, version 4.4.0.0.1.124936715 of the command line tools and R 2.15.1).
>
> Debugging the above program indicates that the error happens in installFunTab(). Not knowing R internals, I can only guess that state from the first embedded instance leaks into the second instance.
>
> Soeren Sonnenburg asked a similar question on March 5th 2009 but there was no reply. He also mentioned a bug report
>
> http://bugs.r-project.org/cgi-bin/R/trashcan?id=12644;user=guest;selectid=12644
>
> but that link no longer works and bug # 12644 is not in the current database.
>
> Can the above mentioned code be made to work?
>
> Thank you,
> Christian
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 30 Aug 2012 - 15:18:17 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 30 Aug 2012 - 20:00:41 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive