You declare that the function should return an int
, but use wrap
which indicates the object returned should be a SEXP
. Moreover, calling an R function from Rcpp
(through Function
) also returns a SEXP
.
You want something like:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
SEXP mySuminC(){
Environment myEnv = Environment::global_env();
Function mySum = myEnv["mySum"];
int x = myEnv["x"];
int y = myEnv["y"];
return mySum(Rcpp::Named("x", x), Rcpp::Named("y", y));
}
(or, leave function return as int
and use as<int>
in place of wrap
).
That said, this is kind of non-idiomatic Rcpp
code. Remember that calling R functions from C++ is still going to be slow.