From wdunlap at tibco.com  Sat Sep 19 00:21:53 2009
From: wdunlap at tibco.com (William Dunlap)
Date: Fri, 18 Sep 2009 15:21:53 -0700
Subject: [Rd] inconsistency in attaching attributes to NULL
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70001CE5F94@NA-PA-VBE03.na.tibco.com>

In R-devel (svn 49628) and back to at least R 2.7.0 we get
inconsistent results when attempting to attach attributes to
a variable with the value NULL.

If we use attributes<- it finishes but changes the value to list().

   > a<-NULL
   > attributes(a)<-list(attr1="First attribute", attr2=2+2i)
   > a
   list()
   attr(,"attr1")
   [1] "First attribute"
   attr(,"attr2")
   [1] 2+2i

If we use attr<- it refuses to attach the attribute

   > b<-NULL
   > attr(b, "attr1") <- "First attribute"
   Error in attr(b, "attr1") <- "First attribute" :
     attempt to set an attribute on NULL

Is the second behavior the correct one and should attributes(x)<-list()
abort if x is NULL?

(attributes(NULL)<-list(attr="First") dies because NULL itself is not
allowed on the left side of an assignment.)

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 



[Rd] inconsistency in attaching attributes to NULL
William Dunlap