[Rcpp-devel] Bug in loadRcppClass/loadModule?

Romain François romain at r-enthusiasts.com
Wed Nov 19 13:49:57 CET 2014


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 <aaronpolhamus at 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 at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20141119/7bc9c4e1/attachment.html>


More information about the Rcpp-devel mailing list