[Rd] Arithmetic not keeping S4-bit on simple extensions
Martin Maechler
maechler at stat.math.ethz.ch
Tue Nov 14 18:07:31 CET 2006
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
More information about the R-devel
mailing list