[Rcpp-devel] help packaging Rcpp modules

Dirk Eddelbuettel edd at debian.org
Wed May 9 01:43:05 CEST 2012


James,

On 8 May 2012 at 17:51, James Simone wrote:
| 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 missed one error here.  You should use the 'module=TRUE' argument, ie
something like

  R> Rcpp.package.skeleton("rcppmod1", path="/tmp", module=TRUE)
  Creating directories ...
  Creating DESCRIPTION ...
  Creating NAMESPACE ...
  Creating Read-and-delete-me ...
  Saving functions and data ...
  Making help files ...
  Done.
  Further steps are described in '/tmp/rcppmod1/Read-and-delete-me'.
  
  Adding Rcpp settings
   >> added RcppModules: yada
   >> added Depends: Rcpp
   >> added LinkingTo: Rcpp
   >> added useDynLib directive to NAMESPACE
   >> added Makevars file with Rcpp settings
   >> added Makevars.win file with Rcpp settings
   >> added example header file using Rcpp classes
   >> added example src file using Rcpp classes
   >> added example R file calling the C++ example
   >> added Rd file for rcpp_hello_world
   >> copied the example module 
  R> 

With that parts work, eg after R CMD INSTALL, the 'World' class works:

  edd at max:/tmp$ r -l rcppmod1 -e'w <- new(World); print(w$greet())'
  [1] "hello"
  edd at max:/tmp$ 
  edd at max:/tmp$ r -l rcppmod1 -e'w <- new(World); w$set("something"); print(w$greet())'
  [1] "something"
  edd at max:/tmp$ 

but unfortunately the rest of the 'yada' modules is not loaded correctly.
(Here r is from my littler project. I use that a lot for cmdline tests.)

Cheers, Dirk


| 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 );
| }
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-- 
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com


More information about the Rcpp-devel mailing list