From romain at r-enthusiasts.com  Fri Jul  5 15:43:27 2013
From: romain at r-enthusiasts.com (romain at r-enthusiasts.com)
Date: Fri, 05 Jul 2013 15:43:27 +0200
Subject: [Rd] Get the tail of a list in C
In-Reply-To: <1373001349875-4670900.post@n4.nabble.com>
References: <1373001349875-4670900.post@n4.nabble.com>
Message-ID: <1fc49b7c8acd4f6b358c3db2d91d5660@r-enthusiasts.com>

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



[Rd] Get the tail of a list in C
romain at r-enthusiasts.com