[R] Error in str(its-object)
Martin Maechler
maechler at stat.math.ethz.ch
Tue Nov 14 17:24:11 CET 2006
>>>>> "StAl" == Albrecht, Dr Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com>
>>>>> on Tue, 14 Nov 2006 15:36:45 +0100 writes:
StAl> Dear all, on my Windows XP R 2.4.0 version with
StAl> Package its version 1.1.4 I have a problem with str()
StAl> applied on an its-object after a simple matrix
StAl> manipulation on the its object (see below). I am not
StAl> sure, whether this a problem with my application, its
StAl> or str().
I'd say mainly with its, and then with R internal arithmetic.
str() actually reveals that the object you produce is not
``valid'' anymore in a certain sense (see below).
StAl> .......... But its object should be able to handle simple matrix
StAl> multiplications, even if the result is a matrix. Any
StAl> help is greatly appreciated.
"/ 1" is not a simple multiplication.
But I agree that package
"its" (which you failed to mention) should make sure that
' <itsObj> / 1 '
should work -- which it does not. Here is a reproducible
example script - extended from your transcript :
--------------------------------------------------------------------------
(mat <- matrix(1:6, 2,3,
dimnames=list(c("2003-01-01","2003-01-04"),letters[1:3])))
library(its)
(im <- its(mat))
str(im)
isS4(im) # TRUE, of course, but ..
isS4(im / 1)# FALSE !!!
## even though
class(im / 1)
## shows
## [1] "its"
## attr(,"package")
## [1] "its"
## and the reason comes from
selectMethod("/", signature(e1 = "its", e2 = "numeric"))
## -> .Primitive("/")
--------------------------------------------------------------------------
So what happens is that the builtin arithmetic *does* work on
the .Data slot automatically -- as it should IIRC the green book
on this topic.
What the builtin arithmetic *fails* to do,
is keeping the S4-object bit.
--> I'll post a version of this to R-devel, since I think we
should consider improving the current behavior here.
For the current version of R, the maintainer of "its" should
really define "Arith" methods for
signature("its", "numeric") and signature("numeric", "its").
Martin Maechler, ETH Zurich
More information about the R-help
mailing list