Skip to content
Prev 841 / 10988 Next

[Rcpp-devel] Assignment and extraction from a Vector in a templated function

Hi,

(just saw I did not pick this one up)

It might be one of those cases where we lack a const version of some 
operator. or maybe the compiler is confused about R_len_t

operator[] are defined as:

inline Proxy operator[]( const int& i ){ return cache.ref(i) ; }
inline Proxy operator[]( const int& i ) const { return cache.ref(i) ; }
	
so perhaps with :

x[ i ] ;

with x a Vector and i a R_len_t, the compiler finds it more suitable to 
convert x to a SEXP and use pointer arithmetics, which is usually the 
reason when it starts to complain about "forward declaration of 'struct 
SEXPREC'

Can you try with int ?
Should we move to use R_len_t as indexers ?

I do plan to have a sugar version of "rev". Actually I think I'll write 
it right after I press "send".

Perhaps we can also accomodate vector indexing so that we can do:

IntegerVector x ;
NumericVector y ;
NumericVector z = y[ x ] ;

We already have something that goes in this direction with the Range class:

"runit_Range" = list(
				signature(  ),
				'
					NumericVector xx(8) ;
					xx[ Range(0,3) ] = exp( seq_len(4) ) ;
					xx[ Range(4,7) ] = exp( - seq_len(4) ) ;
					return xx ;
				'	
			),
			

we can probably extend this to make it possible to index a vector by any 
integer sugar expression, probably also with logical expressions

Romain

Le 30/06/10 17:59, Douglas Bates a ?crit :