[Rcpp-devel] added raw support in RcppSexp

Dirk Eddelbuettel edd at debian.org
Tue Dec 22 12:10:31 CET 2009


(sorry, on-list redirect once more)

On 22 December 2009 at 10:46, Romain François wrote:
| Hi,
| 
| I've just added raw vector support into the RcppSexp class, so it gains:
| 
| RcppSexp(const Rbyte & v);
| RcppSexp(const std::vector<Rbyte> & v);
| std::vector<Rbyte>       asStdVectorRaw() const;
| 
| I've also added the appropriate examples in RcppSexpTests.r

Neat, thanks, particularly

+std::vector<Rbyte> RcppSexp::asStdVectorRaw() const {
+    int n = Rf_length(m_sexp);
+    std::vector<Rbyte> v(n);
+    switch( TYPEOF(m_sexp) ){
+    case RAWSXP:
+    	{
+    		v.assign( RAW(m_sexp), RAW(m_sexp)+n ) ;
+    		break ;
+    	}

I've long wondered why/how/if we could assign more efficiently -- but STL
Vectors don't let us just 'memcpy' a chunk.  

Would this 'more iterator like' assign(a,b) work for the types INTEGER, REAL
too?

Dirk

-- 
Three out of two people have difficulties with fractions.


More information about the Rcpp-devel mailing list