문제

A simple experiment shows that only one RInside instance is allowed per thread at a time.

#include <RInside.h>

int main() {
  RInside R1;
  R1.parseEval("cat('Hello, R1\n')");
  RInside R2;
  R2.parseEval("cat('Hello, R2\n')");
  return 0;
}

The program crashes with the following output:

Hello, R1
terminate called after throwing an instance of 'std::runtime_error'
what():  can only have one RInside instance

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

However the result of another experiment with succesive RInside instances creation is not quite clear.

#include <RInside.h>

int main() {
  RInside *R1 = new RInside();
  R1->parseEval("cat('Hello, R1\n')");
  delete R1;
  RInside *R2 = new RInside();
  R2->parseEval("cat('Hello, R2\n')");
  delete R2;
  return 0;
}

This program buzzes at the moment of R2 creation. The previous output looks like this:

Hello, R1
Lost warning messages

Isn't R1 destructor call sufficient for the proper RInside cleanup?

도움이 되었습니까?

해결책

Please -- that was all just discussed on the rcpp-devel mailing list and here is a link to the entire (short) thread. In a nutshell it is not the RInside destructor but rather the R API itself which RInside merely provides via an easier-to-use C++ wrapping.

A follow-up post has been sent to r-devel as well and in that thread Simon clearly states that because of a number of static globals in R itself, a fix is unlikely.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top