[Rcpp-devel] Bug in loadRcppClass/loadModule?

Dirk Eddelbuettel edd at debian.org
Wed Nov 19 13:46:43 CET 2014


On 18 November 2014 at 20:49, Aaron Polhamus wrote:
| 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? 

Could be -- that ability of loading snippets that got shadowed by Rcpp
Attributes so this aspect may not get much exposure.  And it is similar with
the RcppClass added extension by John ...

So can you try that simple patch?  If you fork and have Travis set up, GitHub
will run all the tests for you...

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list