[R] How to return a big treelike list from .Call Interface (protect stack overflow)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Nov 18 11:39:11 CET 2003


"Jens Oehlschlägel" <joehl at gmx.de> writes:

> I try to create a big treelike list structure using the RDefines/RInternal
> macros. The tree carries information at each node (attribute list) and at each
> leaf (vector). 
> My understanding is that for each node I add to the binary tree I have to
> call 
>   PROTECT(newnode = NEW_LIST(2)); 
> and cannot UNPROTECT before I return the whole tree. Same story for node
> attributes and leaf vectors. However, this way I easily reach the limit of the
> proteckt stack at 10000 (BTW this error is not catched). How can I increase
> the protect stack? Is there a better way to create such an R structure? 
> Can one do C-side recursive list assignment MyList[[c(1,2,1,2,2,1)]] <<-
> NewSEXP without calling the R evaluator?

Nono, protection is recursive. You can UNPROTECT as soon as a
structure becomes part of a PROTECT'ed structure, or even avoid
protection at all if you assign immediately, e.g.

SET_VECTOR_ELT(oldnode,0, newnode=NEW_LIST(2))

I believe the protect stack overflow situation has improved in 1.8.1.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list