[Rd] assigning to a null data frame. (PR#4727)
maechler at stat.math.ethz.ch
maechler at stat.math.ethz.ch
Thu Oct 23 09:22:37 MEST 2003
>>>>> "ashenfluff" == ashenfluff <ashenfluff at yahoo.com>
>>>>> on Wed, 22 Oct 2003 22:29:23 +0200 (MET DST) writes:
ashenfluff> Full_Name: Ben K.
ashenfluff> Version: 1.8.0
ashenfluff> OS: win2k
ashenfluff> Submission from: (NULL) (208.243.20.222)
ashenfluff> This fails:
ashenfluff> vars<-data.frame(NULL)
ashenfluff> vars$delta<-4
ashenfluff> output: Error in "$<-.data.frame"(`*tmp*`, "delta", value = 4) :
ashenfluff> replacement has 1 rows, data has 0
ashenfluff> It worked in 1.7.0 and all previous,
well, I think it was a bug in the way it did "worked", since it
left a very strange object `vars' that certainly wasn't a valid data frame:
Whereas data.frame(NULL) is a valid data.frame, the `vars' resulting fron
vars$delta <- 4 definitely wasn't valid in R 1.7.1 :
it had rownames of length 0 and dimension c(0, 1):
> v <- data.frame(NULL); v$delta <- 4; v
[1] delta
<0 rows> (or 0-length row.names)
> dim(v)
[1] 0 1
> dput(v)
structure(list(delta = 4), .Names = "delta", row.names = character(0), class = "data.frame")
Note that S-plus 6.1.2 has the same problematic behavior as R(<= 1.7.1).
----
I do agree that the data.frame method for "$<-" could be made to
work "properly" here (namely producing a data frame of dimension
(1,1) with rownames = "1").
BTW, I think even more than that I would argue that I'd want
cbind() to work with data.frame(NULL), i.e.,
the following could be made to work
v <- data.frame(NULL)
v <- cbind(v, delta = 4)
(It does work in S+ though there, the 1st statement gives a
warning, and the 2nd gives two warnings ..)
ashenfluff> and if we initialize vars without NULL,
ashenfluff> R is OK with it:
ashenfluff> vars<-data.frame(dummy=4)
ashenfluff> vars$delta<-4
Yes, because in this call to data.frame(.) you
produced a well-dimensioned data.frame with which the "$<-"
operator worked properly.
More information about the R-devel
mailing list