Re: [Rd] append/concatenate an element to a list in C-language

From: Tony Plate <tplate_at_acm.org>
Date: Thu, 18 Oct 2007 20:07:05 -0600

This sounds like it could be dangerous, but if you're sure it's necessary and you know what you are doing, you could investigate whether the "pairlist" internal structure might enable you to do this (AFAIK, a "pairlist" is a traditional linked-list data structure). In general, pairlists seem to be used very little, and I've never seen their use encouraged, so I would be very cautious. You can read more about "pairlists" under ?pairlist, in the R-internals manual, and in the source starting at src/include/Rinternals.h (look for "LISTSXP").

Robert Castelo wrote:
> dear people,
>
> i need to code a function in C working in R and receives two R SEXP
> objects as parameters, where one is a list and another is a vector of
> integers:
>
> void f(SEXP list, SEXP vector) {
>
> ...
>
> return list;
> }
>
>
> and it should return the given list with the integer vector concatenated
> at the end (as the last element of the list). the list can be really big
> so i would not like to create a new list from scratch and copy all the
> elements, including the additional one. i'm also interested in knowing
> how should i properly handle protections of the SEXP objects when doing
> this.

>
> i've been looking at the R source code for everything that has to do
> with CAR, CDR, CONS, and even found functions with promising names like
> listAppend or GrowList but i have not been able to figure this out nor i
> haven't been able to find any reference on how to do this by googling
> all around, so any help will be very much appreciated.

>
>
> thanks a lot!!!
>
> robert.
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 19 Oct 2007 - 02:08:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.