[Rcpp-devel] Modules + Attributes for extensions

fernandohtoledo at gmail.com fernandohtoledo at gmail.com
Tue Mar 6 00:08:55 CET 2018


Dear All,

I working in an R package where the main feature is some classes
exposed through Modules. Besides, the classes constructors and methods,
I am also exporting some functions that take classes instances plus
other parameters to return new classes instances. So far, so good,
everything is working pretty well. 

However, I also would like to share a C++ interface to perspective
users so, they can extend the package with new features that depends on
the classes definitions.

Unfortunately, if toghether with the Module, we have defined a function
that takes as argument classes instances and exporting it through
attributes, the compilation crashes. The error is the same as if after
building, installing and loading and then using sourceCpp the user
inserts the depends attribute for the package, includes the package
header and try by herself new features.

Based on the log I can figure out that it complains by the fact that
there is no as/wrap defined. 

Anyone can give advice on how to circunvent this? The Rcpp_Exports has
always the funtions exported by the attributes first than the module
even if they are in reverse order in the same file. Is it a clue for a
solution?

I have just put a ToyPack that reproduce this error (https://github.com
/FHToledo/ToyPack). In src/Interface.cpp there is a commented chunck
that causes the following error:

[When Building]

...

/usr/local/lib/R/site-library/Rcpp/include/Rcpp/internal/Exporter.h: In
instantiation of ‘Rcpp::traits::Exporter<T>::Exporter(SEXP) [with T =
CC; SEXP = SEXPREC*]’:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:87:51:   required
from ‘T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag)
[with T = CC; SEXP = SEXPREC*]’
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:152:31:   required 
from ‘T Rcpp::as(SEXP) [with T = CC; SEXP = SEXPREC*]’
/usr/local/lib/R/site-
library/Rcpp/include/Rcpp/InputParameter.h:34:43:   required from
‘Rcpp::InputParameter<T>::operator T() [with T = CC]’
RcppExports.cpp:19:59:   required from here
/usr/local/lib/R/site-
library/Rcpp/include/Rcpp/internal/Exporter.h:31:31: error: no matching
function for call to ‘CC::CC(SEXPREC*&)’
       Exporter( SEXP x ) : t(x){}

...

[When Extending]

library(ToyPack)
library(Rcpp)

i <- 10
j <- 20
x <- 2
y <- 2.5

AA <- CA$new(i, j)
BB <- CB$new(x, y)
C1 <- CC$new(AA, BB)
DD <- increase_c(C1, AA, 2, 5.5)

src <- '
// [[Rcpp::depends(ToyPack)]]

# include <cmath>
# include <ToyPack.h>

CC evolve_c(CC old, int minus, double plus) {

  old.a.process(minus) ;
  
  int w(old.a.size) ;
  int z(old.b.get_size() + w) ;
  
  return CC(CA(w, 0), CB(z, M_PI)) ;

}
'

sourceCpp(code = src)

...

/usr/local/lib/R/site-library/Rcpp/include/Rcpp/internal/Exporter.h: In
instantiation of ‘Rcpp::traits::Exporter<T>::Exporter(SEXP) [with T =
CC; SEXP = SEXPREC*]’:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:87:51:   required
from ‘T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag)
[with T = CC; SEXP = SEXPREC*]’
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:152:31:   required 
from ‘T Rcpp::as(SEXP) [with T = CC; SEXP = SEXPREC*]’
/usr/local/lib/R/site-
library/Rcpp/include/Rcpp/InputParameter.h:34:43:   required from
‘Rcpp::InputParameter<T>::operator T() [with T = CC]’
file632c6668acf5.cpp:31:59:   required from here
/usr/local/lib/R/site-
library/Rcpp/include/Rcpp/internal/Exporter.h:31:31: error: no matching
function for call to ‘CC::CC(SEXPREC*&)’
       Exporter( SEXP x ) : t(x){}
       
...

Any help, advice, comment and/or feedback will be extremely helpful. I
will also appreciate if someone point me an R package in which custom
as/wrap are defined!

Thanks in advance,
FH


More information about the Rcpp-devel mailing list