Albrecht, Dr. Stefan (AZ Private Equity Partner)
2006-Nov-14 14:36 UTC
[R] Error in str(its-object)
Dear all, on my Windows XP R 2.4.0 version with Package its version 1.1.4 I have a problem with str() applied on an its-object after a simple matrix manipulation on the its object (see below). I am not sure, whether this a problem with my application, its or str(). Of course, one can make> str(core(its(mat)) / 1)num [1:2, 1:3] 1 2 3 4 5 6 - attr(*, "dimnames")=List of 2 ..$ : chr [1:2] "2003-01-01" "2003-01-04" ..$ : chr [1:3] "a" "b" "c" But its object should be able to handle simple matrix multiplications, even if the result is a matrix. Any help is greatly appreciated. Many thanks in advance, Stefan> mat <- structure(1:6,dim=c(2,3),dimnames=list(c("2003-01-01","2003-01-04"),letters[1:3])) > its(mat)An object of class "its" a b c 2003-01-01 1 3 5 2003-01-04 2 4 6 Slot "dates": [1] "2003-01-01 Westeuropäische Normalzeit" "2003-01-04 Westeuropäische Normalzeit"> str(its(mat))Formal class 'its' [package "its"] with 2 slots ..@ .Data: int [1:2, 1:3] 1 2 3 4 5 6 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "2003-01-01" "2003-01-04" .. .. ..$ : chr [1:3] "a" "b" "c" ..@ dates:'POSIXct', format: chr [1:2] "2003-01-01" "2003-01-04"> str(its(mat) / 1)Error in ob[!is.na(ob)] : (subscript) logical subscript too long> str(its(mat / 1))Formal class 'its' [package "its"] with 2 slots ..@ .Data: num [1:2, 1:3] 1 2 3 4 5 6 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "2003-01-01" "2003-01-04" .. .. ..$ : chr [1:3] "a" "b" "c" ..@ dates:'POSIXct', format: chr [1:2] "2003-01-01" "2003-01-04"> class(its(mat / 1))[1] "its" attr(,"package") [1] "its" ____________________________________ Dr. Stefan Albrecht, CFA Allianz Private Equity Partners GmbH Giselastr. 4 | 80802 Munich | Germany Phone: +49.(0)89.3800.18317 Fax: +49.(0)89.3800.818317 EMail: stefan.albrecht@apep.com <mailto:stefan.albrecht@apep.com> Web: www.apep.com <http://www.apep.com/> Please note my new email address: stefan.albrecht@apep.com <mailto:stefan.albrecht@apep.com> [[alternative HTML version deleted]]
>>>>> "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
I'll update ITS to include that signature. Right now, the only signature for Arith is: signature(e1="its",e2="its"). Thx, Whit> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Martin Maechler > Sent: Tuesday, November 14, 2006 11:24 AM > To: Stefan Albrecht > Cc: r-help at stat.math.ethz.ch > Subject: Re: [R] Error in str(its-object) > > >>>>> "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. >This e-mail message is intended only for the named recipient(s) above. It may contain confidential information. If you are not the intended recipient you are hereby notified that any dissemination, distribution or copying of this e-mail and any attachment(s) is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender by replying to this e-mail and delete the message and any attachment(s) from your system. Thank you.
Albrecht, Dr. Stefan (AZ Private Equity Partner)
2006-Nov-16 11:35 UTC
[R] Error in str(its-object)
Dear all, Many thanks for your help and advice. Now I understand the situation much better. Concerning the multiplication workaround, I would - as already indicated in my first email - prefer to use core() rather than the deviation to a zoo object. (im <- its(mat)) core(im) <- core(im) * scale Best regards, Stefan ____________________________________ Dr. Stefan Albrecht, CFA Allianz Private Equity Partners GmbH Giselastr. 4 | 80802 Munich | Germany Phone: +49.(0)89.3800.18317 Fax: +49.(0)89.3800.818317 EMail: stefan.albrecht at apep.com Web: www.apep.com