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

Robert Castelo robert.castelo at upf.edu
Thu Oct 18 19:41:39 CEST 2007

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

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

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!!!


More information about the R-devel mailing list