[Rcpp-devel] Fwd: package contains overloaded methods in module
Chaomei Lo
chaomeilo at gmail.com
Tue Jul 8 23:37:19 CEST 2014
I think the problem was because the user's module was not loaded in zzz.R
file, and after I added my own module name manually. It works !. However,
I would like to know what is the correct way to do it. When I created the
package, I provided the c++ file of my own as below, is there anyway the
custom module can be added after creating the skeleton package if I
provided a source cpp file. Also if there are more classes and modules in
different .cpp files, should I just have to manually add each of them into
the zzz.R file ?
> library(Rcpp)
> Rcpp.package.skeleton(name="testModule1", cpp_files="./test_module.cpp",
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 './testModule1/Read-and-delete-me'.
Adding Rcpp settings
>> added RcppModules: yada, stdVector, NumEx
>> added Imports: Rcpp
>> added LinkingTo: Rcpp
>> added useDynLib directive to NAMESPACE
>> added importFrom(Rcpp, loadModule) directive to NAMESPACE
>> added importFrom(Rcpp, evalCpp) directive to NAMESPACE
>> copied /people/d3j508/Wyoming/test_module.cpp to src directory
>> added example src file using Rcpp attributes
>> compiled Rcpp attributes
>> added Rd file for rcpp_hello_world
>> copied the example module file
Thanks a lot.
Chaomei
---------- Forwarded message ----------
From: Chaomei Lo <chaomeilo at gmail.com>
Date: Tue, Jul 1, 2014 at 11:29 PM
Subject: package contains overloaded methods in module
To: rcpp-devel at lists.r-forge.r-project.org
I use Romain's example as follows (after /// line). It works fine with the
sourceCpp(..). However, with the package I created, it loaded fine but I
got this error below when I instantiate the class. -Thanks for help.
> library("testModule", lib.loc="/people/me/.Rlibs")
> r <- new( Randomizer )
Error in .getClassFromCache(Class, where) : object 'Randomizer' not found
////////////////////////////////////////////////////////
#include <Rcpp.h>
using namespace Rcpp;
class Randomizer {
public:
Randomizer(){}
NumericVector get( int n ){
RNGScope scope ;
return runif( n, 0.0, 1.0 );
}
NumericVector get( int n, double min ){
RNGScope scope ;
return runif( n, min, 1.0 );
}
NumericVector get( int n, double min, double max ){
RNGScope scope ;
return runif( n, min, max );
}
} ;
RCPP_MODULE(mod){
// helping the compiler disambiguate things
NumericVector (Randomizer::*get_1)(int) = &Randomizer::get ;
NumericVector (Randomizer::*get_2)(int,double) = &Randomizer::get ;
NumericVector (Randomizer::*get_3)(int,double,double) =
&Randomizer::get ;
class_<Randomizer>( "Randomizer" )
.default_constructor()
.method( "get" , get_1 )
.method( "get" , get_2 )
.method( "get" , get_3 )
;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140708/760f98a1/attachment-0001.html>
More information about the Rcpp-devel
mailing list