R-alpha: "[[<-" drops attributes

Douglas Bates (bates@stat.wisc.edu)
Tue, 6 Aug 96 16:08 CDT


Message-Id: <m0untMh-0000ULC@franz.stat.wisc.edu>
Date: Tue, 6 Aug 96 16:08 CDT
From: Douglas Bates <bates@stat.wisc.edu>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: "[[<-" drops attributes

I vaguely recall something like this being discussed before but in
my recent move from Adelaide back to Madison I left the old copies of
e-mail behind.

One way to delete a column from a data frame in S is to re-assign it
as NULL.  In R that drops the other attributes of the result.
 > get("[[<-")
 <primitive: [[<->
 > data(women)
 > class(women)
 [1] "data.frame"
 > attributes(women)
 $names
 [1] "height" "weight"

 $row.names
  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"

 $class
 [1] "data.frame"
 > women$height <- NULL
 > class(women)
 NULL
 > women
 $weight
  [1] 115 117 120 123 126 129 132 135 139 142 146 150 154 159 164
 > attributes(women)
 $names
 [1] "weight"

I haven't had the courage to go in and look at the code for the
primitive and see if I can propose a fix.  :-)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-