1

所以,我一直在尝试将 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 作为参考传递,我做错了什么?

提前致谢。

4

1 回答 1

2

RInside R(int argc, char *argv[]);不是一个对象——它是一个函数声明。试试RInside R(argc, argv);吧。

于 2013-06-25T14:35:00.087 回答