找回密码
 立即注册
查看: 4342|回复: 0

RCPP与Rinside混用问题

[复制链接]
发表于 2017-3-28 09:44:19 | 显示全部楼层 |阅读模式
由于R语言的FOR循环效率问题,最近想把循环改为C++版本,思路如下:
最外围程序是R,执行语句中FOR循环部分用RCPP,C++改写,FOR循环内部还需要调用R的函数,因此又要用到Rinside,在Rinside里再调用原来的R函数。示例代码如下:
more demo.r

library(Rcpp)
aa <- function(xx)
{
   return(xx)
}
sourceCpp(file='demo1.cpp')
ddd <- hello1("ccc")
print(ddd)


[root@C0011 parallel]# more demo1.cpp
#include <Rcpp.h>
#include <string>
#include <RInside.h>

using namespace std;
using namespace Rcpp;

//[[Rcpp::export]]

string hello1(string dd)
{

  RInside R();      
  R["txt"] = "Hello, world!\n";   
  Rcpp::Character xxx = R.parseEvalQ("aa(txt)");

  return xxx;
}


执行,出错,确实不太熟悉这个流程怎么做,各位大侠帮助下哦,多谢
Rscript demo.r
demo1.cpp: In function ?.td::string hello1(std::string)?.
demo1.cpp:14:10: error: invalid types ?.Inside()[const char [4]]?.for array subscript
   R["txt"] = "Hello, world!\n";   
          ^
demo1.cpp:15:3: error: ?.haracter?.is not a member of ?.cpp?
   Rcpp::Character xxx = R.parseEvalQ("aa(txt)");
   ^
demo1.cpp:15:19: error: expected ?.?.before ?.xx?
   Rcpp::Character xxx = R.parseEvalQ("aa(txt)");
                   ^
demo1.cpp:17:10: error: ?.xx?.was not declared in this scope
   return xxx;
          ^
make: *** [demo1.o] Error 1
g++ -I/usr/local/lib64/R/include -DNDEBUG  -I/home/data2/daqi/zlib-1.2.8/include -I/home/data2/daqi/bzip2-1.0.6/include -I/home/data2/daqi/xz-5.2.2/include -I/home/data2/daqi/pcre-8.39/include -I/home/data2/daqi/curl-7.51.0/include  -I"/usr/local/lib64/R/library/Rcpp/include" -I"/home/xuyan/R/parallel"   -fpic  -g -O2  -c demo1.cpp -o demo1.o
Error in sourceCpp(file = "demo1.cpp") :
  Error 1 occurred building shared library.
Execution halted


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|R语言中文网

GMT+8, 2024-11-22 02:55 , Processed in 0.037076 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表