为什么不能将SEXP转换为Rcpp :: NumericMatrix?

时间:2013-08-23 12:53:01

标签: rcpp rinside

我使用R by rinside

std::string cmd = "m <-matrix(c(1:9),nrow=3))";
SEXP proxy =  m_R.parseEvalNT(cmd);
Rcpp::NumericMatrix m(proxy); 

以不寻常的方式终止它的运行时

有人请帮帮我 感谢

1 个答案:

答案 0 :(得分:0)

奇。我玩这个,也有一些运行时错误;现在他们不再出现了。试试这个:

// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
//
// cf http://stackoverflow.com/questions/18403402/
//
// GPL'ed 

#include <RInside.h>                    // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);              // create an embedded R instance 

    std::string cmd = "m <- matrix(c(1:9),nrow=3)";
    Rcpp::NumericMatrix M = R.parseEval(cmd);  // assign mat. M to NumericMatrix
    int n = M.nrow();
    int k = M.ncol();
    std::cout << "All good:" << n << " by " << k << std::endl;

    exit(0);
}

edd@max:~/svn/rinside/pkg/inst/examples/standard$ ./so20130823 
All good:3 by 3
edd@max:~/svn/rinside/pkg/inst/examples/standard$ 

我刚刚复制到examples/standard/目录中作为对make的简单调用,然后构建它。