我有兴趣编写一个能够运行R脚本的C++程序。出于几个设计原因,我想创建一个RInside实例,执行脚本,获取结果并销毁实例;全部在一个线程内。我知道R不是多线程的,并且不能创建多个RInside实例。但是我可以在独立线程中创建单个实例吗?当我试图做到这一点我的代码编译,但我会在运行时出现以下错误:在线程内创建一个RInside实例
Error: C stack usage is too close to the limit
Error: C stack usage is too close to the limit
terminate called after throwing an instance of 'Rcpp::binding_not_found'
what(): binding not found: '.AutoloadEnv'
Aborted
这里是产生错误代码:
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
#include <RInside.h>
void *thread_main(void *args){
RInside R(0,NULL);
/* hope to execute an R script here */
printf("--printing from thread--\n");
return NULL;
}
int main(int argc, char *argv[]){
pthread_t tid;
if(pthread_create(&tid, NULL, thread_main, NULL)){
printf("failed to create thread\n");
return -1;
}
sleep(1);
return 0;
}
我已经尝试设置R_CStackLimit = (uintptr_t)-1
为在Writing R Extension中推荐,但无济于事。
我在运行ubuntu,R版本2.15.2,RInside版本0.2.10。
可以做到这一点吗?还是我必须学习Rserve? 非常感谢!