0

我通过 rinside 使用 R

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

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

任何人请帮助我谢谢

4

1 回答 1

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将构建它。

于 2013-08-23T18:07:37.360 回答