From Heather.Turner at warwick.ac.uk  Fri May  9 19:00:37 2008
From: Heather.Turner at warwick.ac.uk (Dr Heather Turner)
Date: Fri, 09 May 2008 18:00:37 +0100
Subject: [Rd] str and class
Message-ID: <48248335.2020908@warwick.ac.uk>

In previous versions of the gnm package, the terms component of "gnm" 
objects had a "classID" attribute. This caused problems when used with 
str as the following simple example illustrates:

 > x <- 1
 > attr(x, "classID") <- "type1"
 > str(x)
Class 'type1' Class 'type1' Class 'type1' Class 'type1' Class 'type1'
...
  Error: evaluation nested too deeply: infinite recursion / 
options(expressions=)?

The problem is that for S3 objects, str saves attr(object, "class") then 
recalls str on unclass(object) -- any "class" attribute is removed, but 
then the "classID" attribute is recursively picked up by attr(object, 
"class") due to partial matching.

Obviously the solution is to use more sensibly named attributes, but str 
could be made more foolproof by using

attr(object, "class", exact = TRUE)

instead.

Best regards,

Heather

-- 
Dr H Turner
Research Fellow
Dept. of Statistics
The University of Warwick
Coventry
CV4 7AL

Tel: 024 76575870
Fax: 024 76524532
Url: www.warwick.ac.uk/go/heatherturner



[Rd] str and class
Dr Heather Turner