[Rd] Arith ops dropping S4 bit [Was: S4 object does not commute? (PR#13209)]

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Mon, 27 Oct 2008 13:49:25 -0400

On Oct 27, 2008, at 12:25 , Robert.McGehee_at_geodecapital.com wrote:

> Hello all,
> It appears that for the simplest of S4 objects, z+1 does not equal
> 1+z.
> Presumably this is a bug, as 1+z seems to make a malformed object (at
> least malformed as an input to str).

FWIW the difference is that z+1 has the S4 bit set, 1+z does not. The objects are otherwise identical. AFAICS the same behavior is reproducible with any binary arithmetic operator (i.e. non-S4 %op% S4 will produce a result with S4 bit cleared yet valid S4 attributes).

Cheers,
S

>
>> setClass("test", representation("vector"))
> [1] "test"
>> z <- new("test", 1)
>> identical(z+1, 1+z)
> [1] FALSE
>> str(z+1)
> Formal class 'test' [package ".GlobalEnv"] with 1 slots
> ..@ .Data: num 2
>> str(1+z)
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test' Class 'test' Class 'test' Class 'test' Class 'test' Class
> 'test'
> Class 'test' Class 'test' Error: evaluation nested too deeply:
> infinite
> recursion / options(expressions=3D)?
>
>> R.version
> _ =20
> platform x86_64-unknown-linux-gnu =20
> arch x86_64 =20
> os linux-gnu =20
> system x86_64, linux-gnu =20
> status =20
> major 2 =20
> minor 8.0 =20
> year 2008 =20
> month 10 =20
> day 20 =20
> svn rev 46754 =20
> language R =20
> version.string R version 2.8.0 (2008-10-20)
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 27 Oct 2008 - 17:58:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 28 Oct 2008 - 16:30:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive