Rcpp - Define a C++ function that takes an R function and an ellipsis argument -
i have r function bar takes r function foo, defined follows:
foo <- function(x,y) x + y bar <- function(foo, z, ...) z + foo(...) a call bar of form:
bar(foo, 1,2,3) now foo defined above, want create c++ version of bar. here's i've tried:
library(rcpp) cppfunction( ' double bar(function foo, double z, ...) { return z + foo(...); } ') this doesn't work. right way define function in c++?
thanks.
it might easier turn ellipsis list before feeding rcpp
bar <- function(foo, z, ...) { args <- list(...) bar_internal(foo, z, args) } and rcpp function can take rcpp::list instead of ellipsis.
double bar_internal(function foo, double z, list args){ }
Comments
Post a Comment