Get the tail of a list in C
Le 2013-07-05 07:15, maxpar a ?crit?:
Hi, I am write R extensions in C. Now I have a VECSXP variable, so how can I get the tail of it (all but the first one) as a new VECSXP. I tried CDR(), but it gives error. Thanks.
Hello,
A VECSXP is actually an array of pointers, not a linked list. If you
want the tail, you have to allocate new data.
For a simplistic version that does not deal with attributes, names, etc
..., try something like this:
int n = length( x ) - 1 ;
SEXP taildata = PROTECT( allocVector( VECSXP, n ) ) ;
for( int i=0; i<n; i++)
SET_VECTOR_ELT( taildata, i, VECTOR_ELT( x, i ) ) ;
Romain