[R] "undefined slot classes" in package code

Pascal A. Niklaus pascal.niklaus at ieu.uzh.ch
Thu Oct 6 15:36:05 CEST 2011


Dear all,

I am facing a problem (warning message) when building a package that I 
am unable to fix:


* checking whether package ‘myRcppTest’ can be installed ... WARNING
Found the following significant warnings:
   Warning: undefined slot classes in definition of "S4test": 
Rcpptest(class "Rcpp_test")


The package (originally generated with Rcpp.package.skeleton) contains a 
class named "test", in module "test" (see the *.cpp file below). This 
class works fine (I can generate and use objects created with 
new(test$test)).

To extend the functionality of this class, I want to wrap a S4 class 
(named S4test in the minimal example below) around the Rcpp class. The 
idea is to store an instance of the Rcpp-class in a slot (see R file 
below), and provide S4 methods that make use of this internal object.

The problem seems to be that during the check/install process 
"test$test" is not known when this file is processed. However, I could 
not figure out so far how to make "test$test" known within the context 
of this file...

Thanks for your help

Pascal


------------------- cpp file --------------------

#include <Rcpp.h>
using namespace Rcpp ;

RCPP_MODULE(test)
{
   class_<test>("test")
     .constructor()
     .field("value", &test::val)
   ;
}

test::test() {}
test::~test() {}

-------------- R file ---------------------

setClass("S4test",
          representation(
               Rcpptest="Rcpp_test")
);

setMethod(f="initialize",
           signature="S4test",
           definition=function(.Object) {
              .Object at Rcpptest <- new(test$test);
              .Object;
           }
);

newS4test <- function()
{
   new("S4test");
}

--------------------- zzz.R ---------------------

.NAMESPACE <- environment()
test <- new( "Module" )

.onLoad <- function(libname, pkgname)
{
   unlockBinding( "test" , .NAMESPACE )
   assign( "test",  Module( "test" ), .NAMESPACE )
   lockBinding( "test", .NAMESPACE )
}

.onAttach <- function(libname, pkgname) {}
.onUnload <- function(libname, pkgname) {}

---------------- NAMESPACE ----------------

useDynLib(myRcppTest)
exportPattern("^[[:alpha:]]+")
import( Rcpp )



-- 

Pascal A. Niklaus
Institute of Evolutionary Biology and Environmental Studies
University of Zurich
CH-8057 Zurich / Switzerland



More information about the R-help mailing list