I wrote a R program that calls hello1()
, which is an Rcpp function contained in demo2.cpp
program
library(Rcpp)
ssss <- function(dd)
{
return(paste("hello ",dd))
}
sourceCpp(file='demo2.cpp')
currentpath <- "/home/xuyan/R/parallel/"
aaa <-hello1(0,currentpath)
print(aaa)
my demo2.cpp
is :
#include <Rcpp.h>
#include <string>
#include <RInside.h>
using namespace std;
using namespace Rcpp;
// [[Rcpp::export]]
int hello1(int argc,string path)
{
const char *argv[] = {path.c_str()};
RInside R(argc,argv);
R["txt"] = "Hello, world!\n";
R["sourcer"] = "demo.r";
R.parseEvalQ("source(sourcer)");
string str = Rcpp::as<string>(R.parseEval("ssss(txt)"));
cout << "result is" << str << endl;
return(111);
}
I've tried to launch this script with:
Rscript demo.r
I receive the following error:
Error in dyn.load("/tmp/RtmpZl0JKp/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_90cc33eafd15/sourceCpp_2.so") : unable to load shared object '/tmp/RtmpZl0JKp/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_90cc33eafd15/sourceCpp_2.so': /tmp/RtmpZl0JKp/sourceCpp-x86_64-pc-linux-gnu-0.12.10/sourcecpp_90cc33eafd15/sourceCpp_2.so: undefined symbol: _ZN7RInsideD1Ev Calls: sourceCpp -> source -> withVisible -> eval -> eval -> dyn.load Execution halted
In fact, I want to solve slowness of R's for
loop. I have an R program that has a large for
loop and it execute very slowly. So, I want to change that for
loop from R to C++ code. Within the for
loop, I call many R functions. So, I need to call from C++ code to R program. Thus, the order is R to C++ to R, that is R to Rcpp to Rinside, am I wrong?
Why?