From maechler at stat.math.ethz.ch  Tue Nov 14 18:07:31 2006
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue, 14 Nov 2006 18:07:31 +0100
Subject: [Rd] Arithmetic not keeping S4-bit on simple extensions
Message-ID: <17753.63443.281162.678090@stat.math.ethz.ch>

This comes from a posting on R-help where
the poster found that str(.) didn't work on 
     <its-object> / 1
even though  <its-object> / 1  looked like a valid "its" object.

Here is a very short script demonstrating the issue :

##----------------------
setClass("mynum", representation = "numeric")
x <- new("mynum", pi)
x
isS4(x) # TRUE
isS4(x * 1) # FALSE -- but wouldn't it make sense to keep the bit here?

x * 1 # show()s in an ugly way -- just because the S4 bit is missing
##----------------------

I wonder if the behavior of primitive (and other "R-builtin"
functions) shouldn't be enhanced such that the S4 bit (that was
introduced with R version 2.4.0) is kept in simple operations
for objects that have a simple .Data slot [use
showClass("mynum") ] and the R-builtin is working on that slot like
in the above case.

Martin



[Rd] Arithmetic not keeping S4-bit on simple extensions
Martin Maechler