Skip to content
Prev 46168 / 63461 Next

Get the tail of a list in C

Le 2013-07-05 07:15, maxpar a ?crit?:
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