Skip to content
Prev 178904 / 398503 Next

Corrupt data frame construction - bug?

Duncan Murdoch wrote:
well, there is the function `$<-.data.frame`.  why does

    bar$NewCol <- ...

*not* dispatch to $<-.data.frame?  $<- is used on bar, and bar is a data
frame:

    is(bar)
    # "data.frame" ...

    trace('$<-.data.frame')
    bar$foo <- 1
    # no output

    trace('$<-')
    bar$foo <- 1
    # trace: `$<-`(`*tmp*`, foo, value = 1)

(still with the ugly *tmp*-hack)

and, actually, ?'$<-.data.frame' says:

"     ## S3 replacement method for class 'data.frame':
     x$i <- value"
he has *not*:  he has used the "S3 replacement method for class
'data.frame'".  the fact that it didn't work as expected seems to be a
consequence of a bug in the dispatch mechanism.
wasn't?  what wasn't what?  after bar$NewCol <- integer(0), bar is
labelled as a data frame, and it seems to actually *be* a data frame; 
data frame operations seem to work on bar, and the warning from print
bar talks about a corrupt data frame, not a non-data frame. 

or do you mean that bar is not a data frame internally?  that would be a
semantic weirdo where a user successfully performs an operation on a
data frame and gets a zombie.  in any case, looks like a bug.
it's *R* that mislabels things here.  i can't see the user doing any
explicit labelling;  the only stuff used was data.frame() and '$<-.',
which should dispatch to '$<-.data.frame'.  the resulting zombie object
is clearly R's, not the user's, fault.

vQ