Bugzilla – Bug 15299
Binary operations produced bad object bit
Last modified: 2013-04-30 14:05:20 UTC
I'm reporting this here just for the record; I have a fix ready to commit after testing.
Suharto Anggono reported this:
This is just info.
I recently got something like this.
> > x <- factor(c("A","A","B","B"), levels=c("A","B"))
> > y <- factor(c("a","b","a","b"), levels=c("a","b"))
> > table(x, y)[, "a"] / table(x)
The printing indicates that the result is of class 'table'. But, the 'print' method of class 'table' does not print attr(,"class"). It seems that 'print.default' is used in the printing. I am OK with it, just unusual.
The problem is binary operations copy attributes from the second argument (including the class), then from the first (which has no class), then set the object bit based on the first argument. This ends up with an object with a class attribute that is not marked as an object.
I will fix by ignoring the class attribute of the second argument. Other attributes of the second that do not appear in the first will still be copied from the second.
Instead of the fix I suggested originally, I will just set the object bit properly in the result. So if the first operand is a simple vector and the second has a class, the result will have a class.
The fix will go into R-devel and R-patched soon.