无法通过RInside作为参考

时间:2013-06-25 13:48:57

标签: c++ rcpp rinside

所以,我一直在尝试将RInside用于应用程序,但我无法弄清楚这个问题。我已经阅读了这个问题,我认为我做的完全相同:Passing RInside's 'R' instance as a parameter between classes/methods

但不知何故它不起作用,这里是代码示例:

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);

我得到的错误:

/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>)’

我正在做Dirk的Qt示例,将RInside作为参考,我做错了什么?

提前致谢。

1 个答案:

答案 0 :(得分:2)

RInside R(int argc, char *argv[]);不是对象 - 它是一个函数声明。请改为RInside R(argc, argv);