[Rcpp-devel] Problems wrapping stl::vector<int>

Alessandro Mammana mammana at molgen.mpg.de
Fri Jan 3 17:18:02 CET 2014


Dear all,
thank you again for this fantastic library.
Sorry for the very stupid question, I looked before posting, but I
couldn't find anything.
I am encountering a problem when I try to do something very basic: I
am trying to wrap a std::vector<int> to an IntegerVector:

In the file scratchpad.cpp:

// [[Rcpp::export]]
IntegerVector test(){
    std::vector<int> a;
    a.push_back(1);a.push_back(2);a.push_back(3);
    return wrap<IntegerVector>(a);
}

when doing:
>sourceCpp("scratchpad.cpp")

I get the error:

scratchpad.cpp: In function 'Rcpp::IntegerVector test()':
scratchpad.cpp:181:30: error: no matching function for call to
'wrap(std::vector<int>&)'
scratchpad.cpp:181:30: note: candidates are:
In file included from
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/RcppCommon.h:120:0,
                 from
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp.h:27,
                 from scratchpad.cpp:2:
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:924:13:
note: template<class T> SEXPREC* Rcpp::wrap(const T&)
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:924:13:
note:   template argument deduction/substitution failed:
scratchpad.cpp:181:30: note:   cannot convert 'a' (type
'std::vector<int>') to type 'const Rcpp::Vector<13>&'
In file included from
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/RcppCommon.h:120:0,
                 from
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp.h:27,
                 from scratchpad.cpp:2:
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:965:13:
note: template<class InputIterator> SEXPREC* Rcpp::wrap(InputIterator,
InputIterator)
/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include/Rcpp/internal/wrap.h:965:13:
note:   template argument deduction/substitution failed:
scratchpad.cpp:181:30: note:   cannot convert 'a' (type
'std::vector<int>') to type 'Rcpp::Vector<13>'
scratchpad.cpp:183:1: warning: control reaches end of non-void
function [-Wreturn-type]
make: *** [scratchpad.o] Error 1
g++ -I/package/mariux64/R/R-3.0.2/lib/R/include -DNDEBUG
-I/usr/local/include
-I"/package/mariux64/R/R-3.0.2/lib/R/library/Rcpp/include"    -fpic
-g -O3 -Wall -pedantic -c scratchpad.cpp -o scratchpad.o
Error in sourceCpp("scratchpad.cpp") :
Error 1 occurred building shared library.

I must definitely be doing something very stupid. But what?

thanks in advance!
Ale

-- 
Alessandro Mammana, PhD Student
Max Planck Institute for Molecular Genetics
Ihnestraße 63-73
D-14195 Berlin, Germany


More information about the Rcpp-devel mailing list