[Rcpp-devel] Problems wrapping stl::vector<int>
Thanks a lot, it works! I thought I tried to return the variable a directly without template specialization but apparently I didn't T.T However I tried this: IntegerVector x = wrap(a); and it still didn't work... I'll remember this, thanks again! Ale On Fri, Jan 3, 2014 at 5:23 PM, Romain Francois
<romain at r-enthusiasts.com> wrote:
Hello, wrap is for converting an object of arbitrary class to an R object. It deduces what to do based on the class of what you pass it. So you usually don?t specify the template parameter. So you?d usually just write : return wrap(a); If you wanted to be explicit, then you would use: return wrap< std::vector<int> >( a ) ; wrap returns a ? SEXP ? (any R object) which can be used by an IntegerVector constructor. So you can do: IntegerVector x( wrap(a) ) ; or even: IntegerVector = as<IntegerVector>( wrap(a) ) ; Romain Le 3 janv. 2014 ? 17:18, Alessandro Mammana <mammana at molgen.mpg.de> a ?crit :
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
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Alessandro Mammana, PhD Student Max Planck Institute for Molecular Genetics Ihnestra?e 63-73 D-14195 Berlin, Germany