0

を含み、 を使用してコンパイルされたexeファイルに引数を渡そうとしています。RInsidemake

ここからインスピレーションを得たこのコードを使用してください。

#include <RInside.h>

int main(int argc, char *argv[]) {
    // define two vectors in C++
    std::vector<double> x({1.23, 2.34, 3.45});
    std::vector<double> y({2.34, 3.45, 1.23});
    // start R
    RInside R(argc, argv);
    // define a function in R
    R.parseEvalQ("rtest <- function(x, y) {x + y}");
    // transfer the vectors to R
    R["x"] = x;
    R["y"] = y;
    // call the function in R and return the result
    std::vector<double> z = R.parseEval("rtest(x, y)");
    std::cout << z[0] << std::endl;

    // move R function to C++
    Rcpp::Function rtest((SEXP) R.parseEval("rtest"));
    // call the R function from C++
    z = Rcpp::as<std::vector<double>>(rtest(x, y));
    std::cout << z[0] << std::endl;
    exit(0);
}

私は2つの懸念があります:

まず、make -f Makefile.win soraw以下のエラーを出してみてください。なぜ機能しないのですか?

soraw.cpp:21:36: error: '>>' should be '> >' within a nested template argument list
     z = Rcpp::as<std::vector<double>>(rtest(x, y));
                                    ^

次に、 C++ コードで宣言する代わりに、R から (exe にコンパイルした後に) この C++ コードxに渡す最良の方法は何でしょうか? yファイルを使用する必要がありますか?


編集これは、追加のスペースを使用してコンパイルしようとしたときのエラーです:candidate expects 0 arguments, 1 provided

z = Rcpp::as<std::vector<double> >(rtest(x, y));

与える

C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/stl_vector.h:264:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const allocator_type& {aka const std::allocator<double>&}'
C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/stl_vector.h:253:7: note: std::vector<_Tp, _Alloc>::vector() [with _Tp = double; _Alloc = std::allocator<double>]
       vector()
       ^
C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/stl_vector.h:253:7: note:   candidate expects 0 arguments, 1 provided
make: *** [<builtin>: soorig] Error 1

編集:これは、これらの行を変更した後に発生するエラーですMakefile.win

4

1 に答える 1