[Rd] str and class

Dr Heather Turner Heather.Turner at warwick.ac.uk
Fri May 9 19:00:37 CEST 2008


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



More information about the R-devel mailing list