[Rd] Shrinking a List

Saptarshi Guha saptarshi.guha at gmail.com
Thu Mar 11 05:53:32 CET 2010


Hello,
I create a VECSXP(call it A) with size N(~ 5000), i then proceed to
fill the elements and find out I don't need to fill more than
M (M<< N).
Thus if i return A to the user's R code, he/she will see a list of
length 5K of which N-M are NULLs.

To avoid this, I create a new VECSXP B of length M and /duplicate/ the
elements of A.

Since I do this often, it appears to be wasteful, so can I

a) is there a resize function for a VECSXP?

if not

b) can i just do something like

 SET_VECTOR_ELT(B,i, VECTOR_ELT(A,i))  instead of wrapping
VECTOR_ELT(A,i) inside a call to Rf_duplicate
(i will be UNPROTECTING A and B, though I will return B)


I suppose I can do (b), since B (since it is being returned) is
automatically protected and therefore all its elements will also be
protected, correct?


Thank you
Saptarshi



More information about the R-devel mailing list