[Rcpp-commits] r3014 - pkg/playground

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 25 21:37:25 CEST 2011


Author: romain
Date: 2011-04-25 21:37:25 +0200 (Mon, 25 Apr 2011)
New Revision: 3014

Added:
   pkg/playground/cxxmodule.R
Log:
simplify loading up a module from inline

Added: pkg/playground/cxxmodule.R
===================================================================
--- pkg/playground/cxxmodule.R	                        (rev 0)
+++ pkg/playground/cxxmodule.R	2011-04-25 19:37:25 UTC (rev 3014)
@@ -0,0 +1,25 @@
+require( inline )
+require( Rcpp )
+
+cxxmodule <- function( code = paste( readLines( file ), collapse = "\n" ), 
+    ..., 
+    plugin = "Rcpp", file ){
+    
+    fx <- cxxfunction( , '', includes = code, ..., plugin = plugin )
+    
+    lines <- strsplit( code, "\\n")[[1]]
+    modline <- grep( "RCPP_MODULE[(].*[)]", lines, value = TRUE )
+    modname   <- sub( "^.*RCPP_MODULE[(](.*?)[)].*$", "\\1", modline )
+    mod <- Module( modname, getDynLib( fx ), mustStart = TRUE )
+    mod
+}
+
+mod <- cxxmodule( '
+double norm( double x, double y ){
+    return sqrt( x*x + y*y) ;
+}
+RCPP_MODULE(foo){
+    function( "norm", &norm ) ;
+}
+')
+



More information about the Rcpp-commits mailing list