So, I've been trying to use RInside for an application, but I can not figure out this issue. I've read this question, and I think I'm doing the exact same thing: Passing RInside's 'R' instance as a parameter between classes/methods
But somehow it is not working, here is a sample of the code:
pair<Rcpp::NumericVector,int> kmedoids (RInside & R, vector<int> alerts) {
R["M"] = alerts;
string txt = "library(cluster);"
"result <- clara(M, 2);";
R.parseEvalQ(txt);
Rcpp::NumericVector result((SEXP) R.parseEval("res <- result$cluster"));
Rcpp::NumericMatrix clusinfo1 ((SEXP) R.parseEval("clusinfo <- result$clusinfo"));
int biggerCluster = getBiggerCluster(clusinfo1);
pair <Rcpp::NumericVector,int> par;
par.first = result;
par.second = biggerCluster;
return par;
}
RInside R(int argc, char *argv[]);
pair<Rcpp::NumericVector,int> srcIPKmedoid = kmedoids(R, srcIPAmounts);
pair<Rcpp::NumericVector,int> dstIPKmedoid = kmedoids(R, dstIPAmounts);
pair<Rcpp::NumericVector,int> attackClassKmedoid = kmedoids(R, attackClassAmounts);
The error I am getting :
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:442:73: error: invalid initialization of non-const reference of type ‘RInside&’ from an rvalue of type ‘RInside (*)(int, char**)’
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:302:31: error: in passing argument 1 of ‘std::pair<Rcpp::Vector<14>, int> kmedoids(RInside&, std::vector<int>)’
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:443:73: error: invalid initialization of non-const reference of type ‘RInside&’ from an rvalue of type ‘RInside (*)(int, char**)’
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:302:31: error: in passing argument 1 of ‘std::pair<Rcpp::Vector<14>, int> kmedoids(RInside&, std::vector<int>)’
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:444:85: error: invalid initialization of non-const reference of type ‘RInside&’ from an rvalue of type ‘RInside (*)(int, char**)’
/home/renato/workspace/tilera/oads/AM/src/AM.cpp:302:31: error: in passing argument 1 of ‘std::pair<Rcpp::Vector<14>, int> kmedoids(RInside&, std::vector<int>)’
I am doing exactly what Dirk's Qt example does, passing RInside as a reference, what am i doing wrong?
Thanks in advance.
RInside R(int argc, char *argv[]);
isn't an object - it's a function declaration. Try RInside R(argc, argv);
instead.