[Rcpp-devel] package .onLoad multiple modules

Dirk Eddelbuettel edd at debian.org
Sun May 29 18:28:18 CEST 2011


On 29 May 2011 at 18:56, baptiste auguie wrote:
| Dear list,
| 
| [Disclaimer: I am not very familiar with Rcpp/C++, and probably
| haven't followed all the relevant discussions on this list.]
| 
| I'm trying to tidy up two packages on r-forge [*] before submitting
| them to CRAN. In "cda/zzz.r", I have the following code,
| 
| NAMESPACE <- environment()
| cda <- new( "Module" )
| cdatests <- new( "Module" )
| cd <- new( "Module" )
| linear <- new( "Module" )
| array <- new( "Module" )
| 
| .onLoad <- function(libname, pkgname){
|   unlockBinding( "cda" , NAMESPACE )
|   unlockBinding( "cdatests" , NAMESPACE )
|   unlockBinding( "cd" , NAMESPACE )
|   unlockBinding( "linear" , NAMESPACE )
|   assign( "cda", Module( "cda" ), NAMESPACE )
|   assign( "cdatests", Module( "cdatests" ), NAMESPACE )
|   assign( "cd", Module( "cd" ), NAMESPACE )
|   assign( "linear", Module( "linear" ), NAMESPACE )
|   lockBinding( "cda", NAMESPACE )
|   lockBinding( "cdatests", NAMESPACE )
|   lockBinding( "cd", NAMESPACE )
|   lockBinding( "linear", NAMESPACE )
| 
|   unlockBinding( "array" , NAMESPACE )
|   assign( "array", Module( "array" ), NAMESPACE )
|   lockBinding( "array", NAMESPACE )
| 
| }
| 
| It seems to work, but is there something I can/should do to make this
| a wee cleaner?

Have another look at the Rcpp-modules vignette, and/or the third set of
slides ("Advanced Rcpp") from our class in April -- you no longer need the
unlockBinding / lockBinding business as Romain internalized that. The
skeleton-generated packages now just do this in zzz.R:

  .onLoad <- function(pkgname, libname){
      loadRcppModules()
  }

using a 'RcppModules: cda, cdatests, cd, linear, array' declaration in
DESCRIPTION.

The question Laurent raised the other day about spurious warnings from 'R CMD
check' around this still stands though.  Not yet sure what to do there...

Cheers, Dirk

-- 
Gauss once played himself in a zero-sum game and won $50.
                      -- #11 at http://www.gaussfacts.com


More information about the Rcpp-devel mailing list