I am trying to do something like the following via Rcpp
In C++
#include<Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double func(double x, double y) {
return x*y;
}
In R:
g<-function(x){func(x,1)}
integrate(g,lower=0, upper=2)
An error message is returned as "Error in func(x, 1) : expecting a single value." It seems that the function "x*y" is not passed to R from C++ in such a way that it can be used for integration in R. Can someone give me some ideas on how to make it work? (I know such integration can be done directly in C++, but I have to do the integration in R).
Thanks in advance for all helpful comments!