Bug 15299 - Binary operations produced bad object bit
Summary: Binary operations produced bad object bit
Alias: None
Product: R
Classification: Unclassified
Component: Low-level (show other bugs)
Version: R 3.0.0
Hardware: All All
: P5 normal
Assignee: R-core
Depends on:
Reported: 2013-04-30 13:05 UTC by Duncan Murdoch
Modified: 2013-04-30 14:05 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Duncan Murdoch 2013-04-30 13:05:03 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)
  A   B
0.5 0.5
[1] "table"

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.
Comment 1 Duncan Murdoch 2013-04-30 14:05:20 UTC
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.