[Rcpp-devel] package .onLoad multiple modules

baptiste auguie baptiste.auguie at googlemail.com
Sun May 29 08:56:16 CEST 2011


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?

Thanks!

baptiste

[*]: https://r-forge.r-project.org/scm/viewvc.php/pkg/cda/?root=photonics
https://r-forge.r-project.org/scm/viewvc.php/pkg/planar/?root=photonics


More information about the Rcpp-devel mailing list