Hello,
I want to expose a C++ class to R through Rcpp. For that I want to try
out a few examples from the note "Exposing C++ functions and classes
with Rcpp modules" and the book "Seamless R and C++ Integration with
Rpp". But I can't manage to get them work. It ends up with an error.
So this is what I'm doing.
First I create a cpp file with the c++ code from the example. The full
content of the cpp file is below.
------------------------------------------------------------------------------------
#include "Rcpp.h"
using namespace Rcpp;
std::string hello() { return "hello"; }
int bar( int x) { return x*2; }
double foo( int x, double y) { return x*y; }
void bla( ) { Rprintf( "hello\\n" ); }
void bla1( int x) {
Rprintf( "hello (x = %d)\\n", x );
}
void bla2( int x, double y) {
Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y );
}
RCPP_MODULE(yada) {
using namespace Rcpp;
function( "hello" , &hello );
function( "bar" , &bar );
function( "foo" , &foo );
function( "bla" , &bla );
function( "bla1" , &bla1 );
function( "bla2" , &bla2 );
}
------------------------------------------------------------------------------------
Then I run this command:
PKG_CXXFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS=`Rscript -e
'Rcpp:::LdFlags()'` R CMD SHLIB test.cpp
Afterwards I start R and run these commands in R:
------------------------------------------------------------------------------------
require(Rcpp)
yada <- Module("yada")
yada$bar( 2L )
yada$foo( 2L, 10.0 )
yada$hello()
yada$bla()
yada$bla1( 2L)
yada$bla2( 2L, 5.0 )
------------------------------------------------------------------------------------
And it ends up with this error:
------------------------------------------------------------------------------------
Error in Module(module, mustStart = TRUE) :
Failed to initialize module pointer: Error in
FUN("_rcpp_module_boot_yada"[[1L]], ...): no such symbol
_rcpp_module_boot_yada in package .GlobalEnv
------------------------------------------------------------------------------------
This happens all the time with modules. Did I overlook something or
what am I doing wrong?
David
[Rcpp-devel] Error in Module
3 messages · Brötje David, Dirk Eddelbuettel, Romain Francois
On 8 April 2014 at 09:00, Br?tje David wrote:
| This happens all the time with modules. Did I overlook something or | what am I doing wrong? This may not work from command-line use. Our vignette and other documentation stresses use in a package. Please consider that. Your example is pretty the unit test worked each time one runs a full R CMD check on Rcpp -- this works. But as a package. Dirk
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
Hello, Just sourceCpp the .cpp file and use the functions verbatim:
sourceCpp( "/tmp/mod.cpp" ) bar(2L)
[1] 4 If you really want to use the module as an object, you have to pick it up from the right spot:
yada <- Module("yada", where = tail(getLoadedDLLs(), 1)[[1]] )
yada$hello()
[1] "hello" Romain Le 8 avr. 2014 ? 09:00, Br?tje David <d.broetje at tu-braunschweig.de> a ?crit :
Hello,
I want to expose a C++ class to R through Rcpp. For that I want to try out a few examples from the note "Exposing C++ functions and classes with Rcpp modules" and the book "Seamless R and C++ Integration with Rpp". But I can't manage to get them work. It ends up with an error. So this is what I'm doing.
First I create a cpp file with the c++ code from the example. The full content of the cpp file is below.
------------------------------------------------------------------------------------
#include "Rcpp.h"
using namespace Rcpp;
std::string hello() { return "hello"; }
int bar( int x) { return x*2; }
double foo( int x, double y) { return x*y; }
void bla( ) { Rprintf( "hello\\n" ); }
void bla1( int x) {
Rprintf( "hello (x = %d)\\n", x );
}
void bla2( int x, double y) {
Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y );
}
RCPP_MODULE(yada) {
using namespace Rcpp;
function( "hello" , &hello );
function( "bar" , &bar );
function( "foo" , &foo );
function( "bla" , &bla );
function( "bla1" , &bla1 );
function( "bla2" , &bla2 );
}
------------------------------------------------------------------------------------
Then I run this command:
PKG_CXXFLAGS=`Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS=`Rscript -e 'Rcpp:::LdFlags()'` R CMD SHLIB test.cpp
Afterwards I start R and run these commands in R:
------------------------------------------------------------------------------------
require(Rcpp)
yada <- Module("yada")
yada$bar( 2L )
yada$foo( 2L, 10.0 )
yada$hello()
yada$bla()
yada$bla1( 2L)
yada$bla2( 2L, 5.0 )
------------------------------------------------------------------------------------
And it ends up with this error:
------------------------------------------------------------------------------------
Error in Module(module, mustStart = TRUE) :
Failed to initialize module pointer: Error in FUN("_rcpp_module_boot_yada"[[1L]], ...): no such symbol _rcpp_module_boot_yada in package .GlobalEnv
------------------------------------------------------------------------------------
This happens all the time with modules. Did I overlook something or what am I doing wrong?
David
_______________________________________________ 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