[Rcpp-devel] passing function
Davor Cubranic
cubranic at stat.ubc.ca
Wed Jan 26 17:30:48 CET 2011
On 2011-01-26, at 7:38 AM, Dirk Eddelbuettel wrote:
> cpp <- '
> int n = as<int>(N);
> NumericVector numvec(xvec) ;
> Function f(fun) ;
> for( int i=0; i<n; i++){
> numvec = f( numvec ) ;
> }
> return numvec ;
> '
>
> # create a C++ function
> funx <- cfunction(signature(N = "integer" , xvec = "numeric", fun = "function" ),
> cpp, , Rcpp = TRUE, include = "using namespace Rcpp; ")
[...]
> Now for your questions:
>
> I see that f is a Function object but what is fun?
>
> There is no 'fun' but 'funx' is an R function created by cfunction() [ of the
> inline package ] containing executable code created by cfunction() from the
> source code submitted via variable 'cpp'.
I think the question was about the line 'Function f(fun)'.
And the answer is that 'fun' is the second argument of the C++ function, and is an SEXP for the R function passed in. (See the 'signature' call in assignment to 'funx'.) So 'Function f(fun)' creates an instance of Rcpp::Function called 'f' out of the 'fun' SEXP.
Davor
More information about the Rcpp-devel
mailing list