r - 使用 RInside 析构函数

标签 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 清理吗?

最佳答案

——这些都刚刚在 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 本身存在大量静态全局变量,因此不太可能修复。

关于r - 使用 RInside 析构函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12244798/

相关文章:

将 NA 替换为 0,仅在 data.table 中的数字列中

c++ - Rcpp : Magick++ 中的编译器和链接器标志

r - 为什么这个循环和附加到数据框不起作用?

R:为 dplyr 选择每两个连续行

Rcpp::compileAttributes() 错误

r - 使用 Rcpp 找不到消息错误 'C:/Program'

c++ - 无法使用 Armadillo 示例编译 rinside

c++ - RCpp/RInside C++ 主要方法查询和限制?

python - 将公司名称列表变成股票行情