[Rcpp-devel] passing function

Dirk Eddelbuettel edd at debian.org
Tue Jan 25 19:17:20 CET 2011


On 25 January 2011 at 12:01, Siddhartha Chib wrote:
| Is it possible to pass a user defined function
| written in R for use in rccparma.  For example, is it possible to have a

(What is rccparma?)

| function
| SEXP myfunction(SEXP g, SEXP a)
| where g is a function object and a is a
| matrix, the argument of g?

Have you looked at   

     examples/functionCallback/newApiExample.r

which installed with your copy of Rcpp -- it uses Rcpp to sweep a
user-supplied R function over a vector.  Doing this with a matrix is close.

And just for completeness, there is more in other place; my RcppDE riff on
the the DEoptim software allows you to pass objective functions as either R
or C++ functions; the C++ side then needs external pointers.

Hope this helps,  Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list