Skip to content
Prev 27830 / 63424 Next

Losing attributes in data.frame() (PR#10873)

This is a delicate balance.  The crucial part (which you didn't mention) 
is that this only happens if you add a column by df[, "c"] <- value ; if 
you replace the contents of a column then attributes are preserved.

Clearly some attributes like names are invalidated when you extend a list, 
and others may or may not be.  Some parts of R copy all attributes which 
are not obviously invalidated (see mostattributes<-) and others only copy 
those that are obviously valid (and the balance has swung over the years 
towards the first camp).

I'm in the camp that says we are too generous in copying over attributes, 
but here I will make [<- consistent with [[<- and $<-.

Note that e.g. df[, 1:2] drops the attribute, whereas df[,] does not, 
something inherited from lists (and vectors):
$names
[1] "a" "b"
$names
[1] "a" "b"

$foo
[1] 10
On Mon, 3 Mar 2008, gunter.berton at gene.com wrote:

            
I don't think you can expect such detailed documentation -- given how 
little use is made of the documentation we do write no one is going to 
volunteer to write up (and maintain the write up of) such details.