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. -- View this message in context: http://r.789695.n4.nabble.com/Get-the-tail-of-a-list-in-C-tp4670900.html Sent from the R devel mailing list archive at Nabble.com.
Get the tail of a list in C
3 messages · maxpar, Romain Francois
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
Thanks. Got it. I need differentiate pairlist and list. -- View this message in context: http://r.789695.n4.nabble.com/Get-the-tail-of-a-list-in-C-tp4670900p4670958.html Sent from the R devel mailing list archive at Nabble.com.