Inaccessible Exported Rcpp Module

I have an R package called multicool that handles permutations of multisets. Currently, inside, there is a C ++ class, and the initMC call creates a new object of the Multicool class, which can then do whatever I need. However, there is no easy way to free the memory allocated to this object. It doesn't matter for simple use, but I have an application that can call it hundreds of thousands of times.

The solution, I think, is to expose the class to class R using the Rcpp module. However, I tried following the instructions and I get an error message:

Error: 'mcModule' object not found

Initially - I would just open the object and its constructor. This is the definition of my class

#include <Rcpp.h>

using namespace Rcpp;
using namespace std;

class Multicool{
  struct list_el {
    int v;
    struct list_el * n;
  };
  typedef struct list_el item;

  item *h;
  item *t;
  item *i;

  int *m_pnInitialState; 
  int *m_pnCurrState;
  int m_nLength;
  bool m_bFirst;

  public:
   // constructor
  Multicool(IntegerVector x){
    int nx = (int)x.size();
  }
};

RCPP_MODULE(mcModule){
  using namespace Rcpp;

  class_<Multicool>("Multicool")

  .constructor<IntegerVector>()
  ;
}

import(Rcpp)

NAMESPACE

RcppModules: mcModule

DESCRIPTION

loadRcppModules .onLoad

.onLoad <- function(libname, pkgname) {
  loadRcppModules()
}

. Multicool,

> library(multicool)
> Multicool = mcModule$Multicool
Error: object 'mcModule' not found

+4
1

new. . RcppRedis:

RCPP_MODULE(Redis) {
    Rcpp::class_<Redis>("Redis")   

        .constructor("default constructor")  
        [...stuff omitted for brevity...]

    ;
}

R (, demo/)

suppressMessages(library(RcppRedis))

redis <- new(Redis)

redis$foo() .., .

,

mcModule <- new(mcModule)

mcModule$Multicool.

: , loadModule("mcModule", TRUE).

2: , () testRcppModule , ( DESCRIPTION), - R

edd@max:/tmp/rcpp/module$ diff -ru ~/git/rcpp/inst/unitTests/testRcppModule/  testRcppModule/ 
diff -ru /home/edd/git/rcpp/inst/unitTests/testRcppModule/DESCRIPTION testRcppModule/DESCRIPTION
--- /home/edd/git/rcpp/inst/unitTests/testRcppModule/DESCRIPTION        2015-08-26 15:53:03.891830292 -0500
+++ testRcppModule/DESCRIPTION  2015-10-22 21:34:23.716959638 -0500
@@ -10,6 +10,6 @@
 LazyLoad: yes
 Depends: methods, Rcpp (>= 0.8.5)
 LinkingTo: Rcpp
-RcppModules: RcppModuleWorld, stdVector, NumEx
+RcppModules: RcppModuleWorld, stdVector, NumEx, mcModule
 Packaged: 2010-09-09 18:42:28 UTC; jmc

diff -ru /home/edd/git/rcpp/inst/unitTests/testRcppModule/R/zzz.R testRcppModule/R/zzz.R
--- /home/edd/git/rcpp/inst/unitTests/testRcppModule/R/zzz.R    2015-08-26 15:53:03.891830292 -0500
+++ testRcppModule/R/zzz.R      2015-10-22 21:41:41.468532838 -0500
@@ -8,4 +8,5 @@
 loadModule("RcppModuleNumEx", TRUE)
 loadModule("RcppModuleWorld", TRUE)
 loadModule("stdVector", TRUE)
+loadModule("mcModule", TRUE)

Only in testRcppModule/src: multicool.cpp
edd@max:/tmp/rcpp/module$ 

:

$ r --package testRcppModule --eval 'm <- new(mcModule); print(m)'
C++ object <0x757d18> of class 'mcModule' <0x1adeab0>
$ 
+3

Source: https://habr.com/ru/post/1612861/


All Articles