[Rd] .Internal(inspect(x)) gives overly verbose output for reference classes

Duncan Murdoch murdoch.duncan at gmail.com
Thu Mar 8 01:12:45 CET 2012


On 12-03-07 10:37 AM, Duncan Murdoch wrote:
> On 12-03-07 9:52 AM, Richard Cotton wrote:
>> Even for an extremely simple instance of a reference class
>>
>> x<- setRefClass("x")
>> y<- x$new()
>>
>> calling the internal inspect function
>>
>> .Internal(inspect(y))
>>
>> produces enough output that it takes several minutes to print to the
>> console.  (Actually I gave up and terminated the command after ~10
>> mins.  It isn't clear whether the output would eventually complete.)
>>
>> Are reference classes really so complicated inside, or is this a bug?
>>
>> ______________________________________________
>
> If you look at the output, you'll see it's looping.  When I hit Esc, I
> saw that .self is an S4SXP with an attribute .xData which is an
> environment containing the same .self, ad infinitum.
>
> So I'd say it's a bug in inspect().  It can handle the case of an
> environment holding itself, but I think it was written before S4SXPs
> contained themselves, and it looks like it's not checking for that.
>
> I'll take a look if someone else doesn't get there first...

There are a couple of optional arguments to inspect that let you avoid 
this infinite recursion, e.g.

.Internal(inspect(y, 5))

will limit the recursion depth to 5, and that's sufficient for this example.

It would be possible to put loop detection into the function, or default 
to a finite depth, but I'd rather not mess it up:  keeping debugging 
aids simple but powerful seems like a good idea to me.  You can always 
hit Esc to stop the display if it goes into a loop, then set a depth 
limit as above.

Duncan Murdoch



More information about the R-devel mailing list