[Rcpp-commits] r2989 - pkg/Rcpp/inst/doc/Rcpp-modules

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 11 11:54:16 CEST 2011


Author: romain
Date: 2011-04-11 11:54:15 +0200 (Mon, 11 Apr 2011)
New Revision: 2989

Modified:
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
Log:
documenting loadRcppModules

Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-04-11 09:45:14 UTC (rev 2988)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-04-11 09:54:15 UTC (rev 2989)
@@ -1095,27 +1095,24 @@
 import( Rcpp )
 @
 
-Loading the module must happen after the dynamic library of the
-package is loaded. The most appropriate place for this is
-within the \Sexpr{link(".onLoad" )} hook.
+The simplest way to load all functions and classes from a module directly
+into a package namespace is to use the \Sexpr{link("loadRcppModules" )} function
+within the \Sexpr{link(".onLoad" )} body. 
 
 <<eval=FALSE>>=
-# grab the namespace
-NAMESPACE <- environment()
-
 .onLoad <- function(libname, pkgname) {
-    ## load the module and store it in our namespace
-    yada <- Module( "yada" )
-    populate( yada, NAMESPACE  )
+    loadRcppModules()
 }
 @
 
-The call to \texttt{populate} installs all functions and classes from the
-module into the namespace of package.
+This will look in the package's DESCRIPTION file for the \texttt{RcppModules}
+field, load each declared module and populate their contents into the 
+package's namespace. For example, the \pkg{testRcppModule} 
+(part of \pkg{Rcpp}'s testing) package has this declaration:
 
-<<echo=FALSE,eval=TRUE>>=
-options( prompt = "> ", continue = "+ " )
-@
+\begin{verbatim}
+RcppModules: yada, stdVector, NumEx
+\end{verbatim}
 
 \subsubsection{Just expose the module}
 
@@ -1125,9 +1122,6 @@
 a function or a class with the dollar extractor.
 
 <<eval=FALSE>>=
-# grab the namespace
-NAMESPACE <- environment()
-
 yada <- Module( "yada" )
 
 .onLoad <- function(libname, pkgname) {
@@ -1135,7 +1129,11 @@
 }
 @
 
+<<echo=FALSE,eval=TRUE>>=
+options( prompt = "> ", continue = "+ " )
+@
 
+
 \subsection{Support for modules in skeleton generator}
 
 The \Sexpr{link("Rcpp.package.skeleton")} function has been improved to help



More information about the Rcpp-commits mailing list