Skip to content
Prev 6479 / 10988 Next

[Rcpp-devel] Struggling with cppFunction() and clusterExport()

The usual way is to put the function in a package and load the package.

Otherwise, you could do something along these lines

auto_function <- function( code, ... ){
     dots <- list(code, ...)
     function(...){
         do.call( cppFunction, dots )( ... )
     }
}

This way the function knows how to compile itself, for example:

 > fun <- auto_function(' double inner_Cpp(double a){ return 1;  } ' )
# this takes a while the first time
 > fun( 2 )
[1] 1
# this is instant thanks to caching of sourceCpp
 > fun( 2 )
[1] 1

Romain

Le 26/09/13 18:57, Matteo Fasiolo a ?crit :