Skip to content

[Rcpp-devel] loadRcppModules

5 messages · schattenpflanze at arcor.de, Romain Francois, Dirk Eddelbuettel

#
Hello,

I've added an experimental feature to Rcpp minutes ago.

This is to simplify (yet again) dealing with modules. Now, when one 
wants to use C++ functions and classes that are declared in a module, 
the only things you have to do are:

* declare them in the "RcppModules" field of DESCRIPTION file, for 
example (taken from the testRcppModule package, part of Rcpp's testing 
universe):

Package: testRcppModule
Type: Package
Title: Some test examples using Rcpp with the Module feature
Version: 0.1
Date: 2010-09-06
Author: JMC
Maintainer:  <jmc at stat.stanford.edu>
Description: Some examples taken (and perhaps modified) from the Rcpp 
Modules documentation.
License: GPL(>=2)
LazyLoad: yes
Depends: methods, Rcpp (>= 0.8.5)
LinkingTo: Rcpp
RcppModules: yada, stdVector, NumEx
Packaged: 2010-09-09 18:42:28 UTC; jmc

The relevant line being:

RcppModules: yada, stdVector, NumEx




* load them. We used to have to load them individually by calling Module 
and maybe populate. Now, this is simpler. You just need a .onLoad 
function that looks like this:

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

This will load the declared modules, and populate them into your 
package's namespace.

I will update the Rcpp-modules vignette accordingly.

Suggestions, comments, improvements, "what are you  ? nuts !", ... are 
always welcome.

Romain
#
I've also updated the skeleton generator so that loadRcppModules is used
by the the package that is generated.

However, it should be noted that things are directly exported into the 
namespace, where before only the module was exported.

So when you do:

 > Rcpp.package.skeleton( "testmod", module = TRUE )

$ R CMD INSTALL testmod

 > require( testmod )
 > foo()
[1] 1
 > w <- new( World )
 > w$greet()
[1] "hello"
 > w$set( "bonjour")
 > w$greet()
[1] "bonjour"

you can use functions (e.g. foo) or classes (e.g. World ) directly.

Hope this is useful.

Romain

Le 11/04/11 11:41, Romain Francois a ?crit :

  
    
#
That sounds fantastic, thank you! Is the new version already available 
for download?

Best regards,
Peter



Am 11.04.2011 12:14, schrieb Romain Francois:
#
Le 11/04/11 12:24, schattenpflanze at arcor.de a ?crit :
No

  
    
#
On 11 April 2011 at 12:25, Romain Francois wrote:
| Le 11/04/11 12:24, schattenpflanze at arcor.de a ?crit :
| > That sounds fantastic, thank you! Is the new version already available
| > for download?
| 
| No

But we should have a version 0.9.4 really soon in just a few days.

Dirk