[R] Error in str(its-object)

Gabor Grothendieck ggrothendieck at gmail.com
Tue Nov 14 17:51:51 CET 2006


A workaround if you need to multiply an its object by a number would
be to convert the its object to zoo, do the multiply on the zoo object
and then convert the resulting zoo object back to its.  Using im from
Martin's example:

library(its)
library(zoo)
im
as.its(3 * as.zoo(im))

On 11/14/06, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
> >>>>> "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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list