Skip to content
Prev 10904 / 63421 Next

assigning to a null data frame. (PR#4727)

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):
[1] delta
<0 rows> (or 0-length row.names)
[1] 0 1
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.