Skip to content
Prev 6353 / 10988 Next

[Rcpp-devel] Problem exposing constructor taking std::vector of user defined class to R using Rcpp-attributes and Rcpp-modules

Hello,

The compiler tells you that :

Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/internal/export.h:90: 
error: no matching function for call to 
?export_range__dispatch(SEXPREC*&, __gnu_cxx::__normal_iterator<B*, 
std::vector<B, std::allocator<B> > >&, Rcpp::traits::r_type_generic_tag)?

The important thing to see here is "r_type_generic_tag"


We currently only have versions of export_range__dispatch for these:

-- strings:

template <typename InputIterator, typename value_type>
void export_range__dispatch( SEXP x, InputIterator first, 
::Rcpp::traits::r_type_string_tag )

-- primitive types (double, int, ...):

template <typename InputIterator, typename value_type>
void export_range__dispatch( SEXP x, InputIterator first, 
::Rcpp::traits::r_type_primitive_tag )
		
So we need one for the r_type_generic_tag :

template <typename InputIterator, typename value_type>
void export_range__dispatch( SEXP x, InputIterator first, 
::Rcpp::traits::r_type_generic_tag )


I just added it in svn. So now your code almost compiles. I did get a

Symbol not found: __ZN1AI1BEC1ESt6vectorIS0_SaIS0_EE

which is:

$ c++filt __ZN1AI1BEC1ESt6vectorIS0_SaIS0_EE
A<B>::A(std::vector<B, std::allocator<B> >)

which I can quickly correct by implementing the constructor:

A( std::vector<T> in_vec ) : vec_of_T(in_vec){}


Then I can do this:

# Reference Class of B
B_R <- setRefClass( "B_R",
     fields = list(id="numeric")
)
b1 <- new( "B_R", id = 1 )
b2 <- new( "B_R", id = 1 )
a <- new( A, list(b1,b2) )


Romain


Le 22/08/13 01:21, Luke.Domanski at csiro.au a ?crit :