[Rcpp-commits] r2987 - in pkg/Rcpp: . R inst inst/unitTests/testRcppModule inst/unitTests/testRcppModule/R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 11 11:34:06 CEST 2011


Author: romain
Date: 2011-04-11 11:34:06 +0200 (Mon, 11 Apr 2011)
New Revision: 2987

Added:
   pkg/Rcpp/R/loadRcppModules.R
   pkg/Rcpp/man/loadRcppModules.Rd
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/inst/NEWS
   pkg/Rcpp/inst/unitTests/testRcppModule/DESCRIPTION
   pkg/Rcpp/inst/unitTests/testRcppModule/R/zzz.R
Log:
new R function : loadRcppModules

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/ChangeLog	2011-04-11 09:34:06 UTC (rev 2987)
@@ -1,3 +1,13 @@
+2011-04-11  Romain Francois  <romain at r-enthusiasts.com>
+
+	* R/loadRcppModules.R: New R function "loadRcppModules" that looks for
+	the "RcppModules" field in the DESCRIPTION file, loads and populates
+	the modules into the package NAMESPACE
+	
+	* man/loadRcppModules.Rd: documentation
+	
+	* inst/unitTests/testRcppModule: using loadRcppModules
+
 2011-04-09  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/CITATION: Finalized using JSS data on volume, number, pages

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/DESCRIPTION	2011-04-11 09:34:06 UTC (rev 2987)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.9.3
+Version: 0.9.3.1
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, 
  with contributions by Douglas Bates and John Chambers

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/NAMESPACE	2011-04-11 09:34:06 UTC (rev 2987)
@@ -1,29 +1,4 @@
-useDynLib(Rcpp, .registration = TRUE
-    # .Call functions
-    ## as_character_externalptr,
-    
-    ## CppField__get, CppField__set,
-    
-    ## Class__name, Class__has_default_constructor,
-    
-    ## CppClass__complete, CppClass__methods,
-    
-    ## Module__classes_info,Module__complete,Module__get_class,
-    ## Module__has_class,Module__has_function, Module__functions_arity,
-    ## Module__functions_names,
-    ## Module__name, Module__get_function, 
-    ## CppObject__finalize, 
-    
-    ## get_rcpp_cache, # init_Rcpp_cache,
-    ## reset_current_error, 
-    ## rcpp_error_recorder, rcpp_set_current_error, rcpp_get_current_error, 
-    ## rcpp_set_error_occured, rcpp_get_error_occured, 
-    ## rcpp_set_stack_trace, rcpp_get_stack_trace,
-    
-    ## # .External functions
-    ## CppMethod__invoke, CppMethod__invoke_void, CppMethod__invoke_notvoid, 
-    ## InternalFunction_invoke, Module__invoke, class__newInstance
-)
+useDynLib(Rcpp, .registration = TRUE)
 
 import( methods )
 importFrom( utils, capture.output, assignInNamespace, .DollarNames, prompt, packageDescription )
@@ -40,6 +15,6 @@
 exportMethods( prompt, show, .DollarNames, initialize, "formals<-" )
 
 export( 
-    Module, Rcpp.package.skeleton, populate
+    Module, Rcpp.package.skeleton, populate, loadRcppModules
 )
 

Added: pkg/Rcpp/R/loadRcppModules.R
===================================================================
--- pkg/Rcpp/R/loadRcppModules.R	                        (rev 0)
+++ pkg/Rcpp/R/loadRcppModules.R	2011-04-11 09:34:06 UTC (rev 2987)
@@ -0,0 +1,35 @@
+
+loadRcppModules <- function(){
+   # hunt for the namespace of the package that calls this
+   calls <- sys.calls()
+   w <- which( sapply( calls, function(call){
+      identical( call[[1L]], as.name( "runHook" ) ) 
+   } ) )
+   if( !length(w) ) 
+    stop( "loadRcppModules can only be used within a .onLoad function" )
+   w <- tail( w, 1L )
+   call <- calls[[w]]
+   if( !identical( call[[2L]], ".onLoad" ) ) 
+    stop( "loadRcppModules can only be used within a .onLoad function" )
+   f <- sys.frame( w )
+   ns <- get("env", f )
+   if( !isNamespace( ns ) ) 
+    stop( "loadRcppModules not called from a namespace" )
+   pkg <- get( "pkgname", f )
+    
+   # look for declared modules in the DESCRIPTION fields
+   description <- packageDescription( pkg )
+   modules <- description[["RcppModules"]]
+   if( !is.null( modules ) ){
+        modules <- strsplit( modules, "[[:space:]]*,[[:space:]]*")[[1L]]
+        for( m in modules ){
+            tryCatch( {
+                mod <- Module( m, pkg, mustStart = TRUE)
+                populate( mod, ns )
+            }, error = function(e){
+                stop( sprintf( "failed to load module %s from package %s", m, pkg ) )  
+            })
+        }
+   }
+    
+}

Modified: pkg/Rcpp/inst/NEWS
===================================================================
--- pkg/Rcpp/inst/NEWS	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/inst/NEWS	2011-04-11 09:34:06 UTC (rev 2987)
@@ -1,3 +1,9 @@
+0.9.4   (future)
+
+    o   new R function "loadRcppModules" to load Rcpp modules automatically
+        from a package. This function must be called from the .onLoad function
+        and works with the "RcppModules" field of the package's DESCRIPTION file
+
 0.9.3   2011-04-05
 
     o   Fixed a bug in which modules code was not behaving when compiled 

Modified: pkg/Rcpp/inst/unitTests/testRcppModule/DESCRIPTION
===================================================================
--- pkg/Rcpp/inst/unitTests/testRcppModule/DESCRIPTION	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/inst/unitTests/testRcppModule/DESCRIPTION	2011-04-11 09:34:06 UTC (rev 2987)
@@ -10,4 +10,6 @@
 LazyLoad: yes
 Depends: methods, Rcpp (>= 0.8.5)
 LinkingTo: Rcpp
+RcppModules: yada, stdVector, NumEx
 Packaged: 2010-09-09 18:42:28 UTC; jmc
+

Modified: pkg/Rcpp/inst/unitTests/testRcppModule/R/zzz.R
===================================================================
--- pkg/Rcpp/inst/unitTests/testRcppModule/R/zzz.R	2011-04-11 08:32:15 UTC (rev 2986)
+++ pkg/Rcpp/inst/unitTests/testRcppModule/R/zzz.R	2011-04-11 09:34:06 UTC (rev 2987)
@@ -1,8 +1,6 @@
 NAMESPACE <- environment()
 
 .onLoad <- function(libname, pkgname){
-    populate( Module("yada"), NAMESPACE )
-    populate( Module("stdVector"), NAMESPACE )
-    populate( Module("NumEx"), NAMESPACE )
+    loadRcppModules()
 }
 

Added: pkg/Rcpp/man/loadRcppModules.Rd
===================================================================
--- pkg/Rcpp/man/loadRcppModules.Rd	                        (rev 0)
+++ pkg/Rcpp/man/loadRcppModules.Rd	2011-04-11 09:34:06 UTC (rev 2987)
@@ -0,0 +1,20 @@
+\name{loadRcppModules}
+\alias{loadRcppModules}
+\title{
+Loads Rcpp modules on package startup
+}
+\description{
+Function to simplify loading Rcpp modules contained in a package. 
+This function must be called from the \code{.onLoad} function of a package. 
+It uses the \code{RcppModules} field of the package \code{DESCRIPTION} file
+to query the names of the modules that the package should export, loads each module, 
+and \code{\link{populate}} each module into the package NAMESPACE.
+}
+\usage{
+loadRcppModules()
+}
+\seealso{
+    \code{\link{populate}}
+}
+\keyword{interface}
+



More information about the Rcpp-commits mailing list