[Rcpp-devel] Bug in loadRcppClass/loadModule?

Aaron Polhamus aaronpolhamus at gmail.com
Wed Nov 19 05:49:48 CET 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20141118/40c5d080/attachment.html>


More information about the Rcpp-devel mailing list