[Rcpp-devel] added raw support in RcppSexp

Romain François francoisromain at free.fr
Wed Dec 23 10:40:11 CET 2009


On 12/22/2009 01:39 PM, Dirk Eddelbuettel wrote:
>
> On 22 December 2009 at 12:15, Romain François wrote:
> |>  I've long wondered why/how/if we could assign more efficiently -- but STL
> |>  Vectors don't let us just 'memcpy' a chunk.
> |
> | I don't think you are guaranteed that the elements are contiguous, so I
> | would not go down there.
>
> Right. I R they are, in STL not necessarily.
>
> |>  Would this 'more iterator like' assign(a,b) work for the types INTEGER, REAL
> |>  too?

Actually it does. input and output iterator do not have to point to the 
same type, si it is valid to do :

std::vector<double> v(n);
v.assign( INTEGER(m_sexp), INTEGER(m_sexp)+n) ;

the values are cast to double implicitely.

I've commited this and also using the copy algorithm from to go the 
other way:

RcppSexp::RcppSexp(const std::vector<int> & v) {
     logTxt("RcppSexp from int vector\n");
     int n = v.size();
     m_sexp = Rf_allocVector(INTSXP, n);
     R_PreserveObject(m_sexp);
     copy( v.begin(), v.end(), INTEGER(m_sexp) ) ;
}

and expanded the tests to make sure the implicit cast works.


> | yep. I derived this from reading item 5 of Effective STL, and how the
> | author is rambling about using range functions rather than looping around.
> |
> | a and be can be int* which is what INTEGER(x) would give you.
>
> Maybe I'll peek and poke. Though I had hope to put work on Rcpp to rest for
> it to get to other stuff :)
>
> Saw that CPP is on R-Forge. Makes sense for now; we'll get to revisit CPP and
> Rcpp and all that with RProtoBuf a few times over anyway...
>
> Dirk
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/IlMh : CPP package: exposing C++ objects
|- http://tr.im/HlX9 : new package : bibtex
`- http://tr.im/Gq7i : ohloh





More information about the Rcpp-devel mailing list