使用RInside析构函数

时间:2012-09-03 08:59:07

标签: r rcpp rinside

一个简单的实验表明,每个线程一次只允许一个RInside实例。

#include <RInside.h>

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

程序崩溃并输出以下内容:

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.

然而,另一个成功创建RInside实例的实验结果并不十分清楚。

#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;
}

这个程序在R2创建的那一刻嗡嗡作响。之前的输出如下所示:

Hello, R1
Lost warning messages

R1析构函数调用是否足以进行正确的RInside清理?

1 个答案:

答案 0 :(得分:3)

- 这些都是在rcpp-devel邮件列表and here is a link to the entire (short) thread上讨论过的。简而言之,它不是不是的RInside析构函数,而是而不是R API本身,而RInside只是通过更易于使用的C ++包装提供。

A follow-up post has been sent to r-devel as well并且在那个帖子中,Simon明确指出由于R本身有许多静态全局变量,因此不太可能修复。