|
由于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
|
|