Message-ID: <1fc49b7c8acd4f6b358c3db2d91d5660@r-enthusiasts.com>
Date: 2013-07-05T13:43:27Z
From: Romain Francois
Subject: Get the tail of a list in C
In-Reply-To: <1373001349875-4670900.post@n4.nabble.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