From murdoch.duncan at gmail.com  Sun Oct 14 13:53:09 2012
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Sun, 14 Oct 2012 07:53:09 -0400
Subject: [Rd] How deep can/should lists be nested?
In-Reply-To: <CAPp_+=f2tkG2nZ-bctBDdg41AEZsgvAmM0Qt4X8g3F5U=XA59w@mail.gmail.com>
References: <CAPp_+=f2tkG2nZ-bctBDdg41AEZsgvAmM0Qt4X8g3F5U=XA59w@mail.gmail.com>
Message-ID: <507AA7A5.4060109@gmail.com>

On 12-10-14 7:06 AM, Richard Cotton wrote:
> I started idly wondering how deeply lists could be nested, and
> couldn't find an explicit limit in the documentation.  With this
> simple test
>
> a_list <- list()
> count <- 0
> repeat
> {
>    a_list[[1]] <- a_list
>    count <- count + 1
> }
>
> my (Win7, R-2.16.0 devel) machine threw an error when count got close to 25000.
>
> The error that stopped it was
>
> Error: protect(): protection stack overflow
>
> I don't know how easy it would be to stop such an error occuring, and
> it probably isn't that useful to be able to nest lists any further.  I
> do think it might be useful for users to be able to know how deeply
> they can nest lists though.
>
> Perhaps it would be better to limit nesting to the value of
> getOption("expressions").  Does anyone have any strong feelings on
> what the correct behaviour should be?

There should be no limit other than memory.  That overflow you saw is a 
bug.  Not sure it's worth fixing, since 25000 is far beyond any sensible 
nesting level, but I'll take a look.

Duncan Murdoch



[Rd] How deep can/should lists be nested?
Duncan Murdoch