What I want to do is similar to this question. That is, passing a function as a parameter. But I want to implement it in Armadillo in R.
I found this answer to be relevant, as it is an implementation in C++. However, after I pasted the code to Armadillo in R and ran it, the following error showed up
"no viable conversion from returned value of type 'std::__1::__nat' to function return type 'double'".
Here is my code
#include <Rcpp.h>
#include <functional>
// [[Rcpp::export]]
double Combiner(double a, double b, std::function<double (double,double)> func){
return func(a,b);
}
double Add(double a, double b){
return a+b;
}
double Mult(double a, double b){
return a*b;
}
/*** R
Combiner(12,13,Add)
Combiner(12,13,Mult)
*/
What is wrong with my code? or is there any other method to "passing function as a parameter in Armadillo in R"? Thanks!