sourceCpp knows how to deal with modules, i.e.: 

inc <- '
#include <Rcpp.h>
using namespace Rcpp;
double norm( double x, double y ) {
    return sqrt( x*x + y*y );
}
RCPP_MODULE(mod) {
    function( "norm", &norm ); 
}'
sourceCpp( code = inc )

giving: 

> norm( 3, 3 )
[1] 4.242641

Romain

> Le 19 nov. 2014 à 05:49, Aaron Polhamus <aaronpolha...@gmail.com> a écrit :
> 
> Dear list, 
> 
> In the process of writing a comprehensive unit testing application for Rcpp I 
> may have come across a bug in the code. It seems to me that the following 
> block should execute just fine, exporting the C++ class "norm" to the global 
> environment: 
> 
> require(inline)
> require(Rcpp) 
> 
> inc <- '
> using namespace Rcpp;
> double norm( double x, double y ) {
>     return sqrt( x*x + y*y );
> }
> RCPP_MODULE(mod) {
>     function( "norm", &norm ); 
> }'
> 
> fx <- cxxfunction(signature(), plugin="Rcpp", include=inc)
> mod <- Module("mod", getDynLib(fx))
>   
> loadRcppClass('norm', 'norm', mod)
> 
> Wh​at happens, though, is that the following error is returned: 
> 
> Error in as.environment(pos) : 
>   no item called "moduleName" on the search list
> 
> D​igging in to loadRcppClass, I find that the function fails at the line: 
> 
> mod <- loadModule(module, NULL, env = where, loadNow = TRUE)
> ​
> Entering loadModule, the function fails here, at the "get" statement: 
> 
> loadM <- as.environment(module)
> module <- get(loadM, "moduleName")
> 
> Isn't this backward? get syntax is:
> 
> get(x, pos = -1, envir = as.environment(pos), mode = "any",
>     inherits = TRUE)
> 
> Where "x" is the object sought in the specified environment. In this case, 
> the function is failing because it can't find moduleName in the environment's 
> search list, but the reason for this seems to be that the current statement 
> is search for an environment within a character string, rather than a 
> character string representing a named object within an environment. 
> 
> Is this in need of a patch, or am I missing something obvious? 
> 
> Cheers, 
> Aaron 
> 
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel@lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to