[Rcpp-devel] help packaging Rcpp modules

James Simone simone at fnal.gov
Wed May 9 00:51:44 CEST 2012


I have followed the Rcpp developer's recommendation that a package
greatly simplifies using RCPP_MODULE wrappering. Unfortunately, I'm
having difficulty building and checking even a simple package
containing an Rcpp module. I have read previous posts on this topic
but I did not find anything helpful. I must be overlooking something
very simple, please help.

The package check fails with this error:
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'mod', details:
   call: value[[3L]](cond)
   error: failed to load module mod from package mod
no binding for "norm"

The package skeleton was created with Rcpp.package.skeleton() to which
I added a C++ source file and then edited files according to the
'Read-and-delete-me' file.

Here are my build and check steps:

$ R CMD build mod
* checking for file `mod/DESCRIPTION' ... OK
* preparing `mod':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building `mod_1.0.tar.gz'

$ R CMD check mod
* using log directory '/home/simone/R/Rcpp/module/mod.Rcheck'
* using R version 2.13.1 (2011-07-08)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file 'mod/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'mod' version '1.0'
* checking package name space information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for executable files ... OK
* checking whether package 'mod' can be installed ... ERROR
Installation failed.

The package skeleton was created with Rcpp.package.skeleton().

Here is the module directory structure:
$ /bin/ls -R mod
mod:
DESCRIPTION  man  NAMESPACE  R  Read-and-delete-me  src

mod/man:
mod-package.Rd

mod/R:
zzz.R

mod/src:
Makevars  Makevars.win  rcpp_module.cpp

Here are the key files:

$ cat mod/NAMESPACE
useDynLib(mod)
exportPattern("^[[:alpha:]]+")
import( Rcpp )

$ cat mod/R/zzz.R

.onLoad <- function(libname, pkgname) {
     require("methods", character=TRUE, quietly=FALSE)
     loadRcppModules()
}

$ cat mod/src/rcpp_module.cpp
#include <math.h>
#include <Rcpp.h>

double norm( double x, double y ) {
   return sqrt( x*x + y*y );
}

RCPP_MODULE(mod) {
   using namespace Rcpp;
   function( "norm", &norm );
}


More information about the Rcpp-devel mailing list