<div dir="ltr">Hi, <div><br></div><div>Have you considered using the function as.matrix? It is an R function but you can call it from within your Rcpp code as well. Once you have a matrix you can use your matrix solution. </div><div><br></div><div>Rgds</div><div>Sameer</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, May 19, 2016 at 5:46 AM Paul Saary <<a href="mailto:rcpp@paulsaary.de">rcpp@paulsaary.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I have been trying to solve this problem for quite some time now, so I<br>
thought I'd ask here.<br>
<br>
I am trying to write a Cpp function, accepting multiple input types,<br>
such as matrices and dataframes.<br>
<br>
I understood that I could do this by accepting any SEXP object.<br>
<br>
The core problem now is to transform these object into something my<br>
software can use, which would be an object of type<br>
std::vector<vector<double>>.<br>
<br>
Currently my function looks like this:<br>
<br>
List handleRObject(SEXP Robj){<br>
        std::vector<vector<double>> internalMatrix;<br>
<br>
        // convert Robj to internalMatrix<br>
        // thats where I am stuck<br>
<br>
        // do some stuff and return List<br>
        return(wrap(someoutput))<br>
}<br>
<br>
I tried many differnt things (using as, switch statements, etc...), but<br>
I do not seem to fully grasp on how tonhandle this problem, as none of<br>
them worked.<br>
<br>
I can transform a NumericMatrix using this code, but could not addapt<br>
this to a more general approach.<br>
<br>
        // use rMatrix as input<br>
        int nc = rMatrix.ncol();<br>
        internalMatrix.resize(nc);<br>
        for( int i=0; i<nc; i++){<br>
            NumericMatrix::Column col = rMatrix(_,i) ;<br>
            internalMatrix[i].assign( col.begin() , col.end() ) ;<br>
        }<br>
<br>
I though, maybe someone can give me a hint on how to solve this?<br>
<br>
Bests,<br>
<br>
Paul<br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</blockquote></div>