[Rd] [<-.POSIXlt changes order of attributes (PR#9197)

gregor.gorjanc at bfro.uni-lj.si gregor.gorjanc at bfro.uni-lj.si
Fri Sep 1 13:58:39 CEST 2006


This is a multi-part message in MIME format.
--------------090203020600020104020707
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello!

I was doing some tests with identical() and found out that [<-.POSIXlt
method changes order of attributes. This example shows that:

x <- strptime("1900-1-1", format="%Y-%m-%d")
x <- c(x)
y <- c(x, x+1)
x1 <- x
y1 <- y

attributes(x)
$names
[1] "sec"   "min"   "hour"  "mday"  "mon"   "year"  "wday"  "yday"  "isdst"

$class
[1] "POSIXt"  "POSIXlt"

$tzone
[1] ""     "CET"  "CEST"

identical(attributes(x), attributes(y))
TRUE

x[1] <- NA
attributes(x)
$names
[1] "sec"   "min"   "hour"  "mday"  "mon"   "year"  "wday"  "yday"  "isdst"

$tzone
[1] ""     "CET"  "CEST"

$class
[1] "POSIXt"  "POSIXlt"

y[1] <- NA
attributes(y)
$names
[1] "sec"   "min"   "hour"  "mday"  "mon"   "year"  "wday"  "yday"  "isdst"

$tzone
[1] ""     "CET"  "CEST"

$class
[1] "POSIXt"  "POSIXlt"

identical(attributes(x), attributes(x1))
FALSE

identical(attributes(y), attributes(y1))
FALSE

This can be solved with either:

Index: R/src/library/base/R/datetime.R
===================================================================
--- R/src/library/base/R/datetime.R     (revision 39045)
+++ R/src/library/base/R/datetime.R     (working copy)
@@ -713,10 +713,10 @@
 {
     if(!as.logical(length(value))) return(x)
     value <- as.POSIXlt(value)
-    cl <- oldClass(x)
+    att <- attributes(x)
     class(x) <- class(value) <- NULL
     for(n in names(x)) x[[n]][i] <- value[[n]]
-    class(x) <- cl
+    attributes(x) <- att
     x
 }

or in the same way as it is done in [.<-POSIXct method

Index: R/src/library/base/R/datetime.R
===================================================================
--- R/src/library/base/R/datetime.R     (revision 39045)
+++ R/src/library/base/R/datetime.R     (working copy)
@@ -714,9 +714,11 @@
     if(!as.logical(length(value))) return(x)
     value <- as.POSIXlt(value)
     cl <- oldClass(x)
+    tz <- attr(x, "tzone")
     class(x) <- class(value) <- NULL
     for(n in names(x)) x[[n]][i] <- value[[n]]
     class(x) <- cl
+    attr(x, "tzone") <- tz
     x
 }

I have checked both versions in r-devel with make check-all and all went
fine.

Regards, Gregor


-- 
Lep pozdrav / With regards,
    Gregor Gorjanc

----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty
Zootechnical Department     URI: http://www.bfro.uni-lj.si/MR/ggorjan
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si

SI-1230 Domzale             tel: +386 (0)1 72 17 861
Slovenia, Europe            fax: +386 (0)1 72 17 888

----------------------------------------------------------------------
"One must learn by doing the thing; for though you think you know it,
 you have no certainty until you try." Sophocles ~ 450 B.C.
----------------------------------------------------------------------

--------------090203020600020104020707
Content-Type: application/x-gzip;
 name="datetime.R.patchVer1.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="datetime.R.patchVer1.gz"

H4sICH7v90QCA2RhdGV0aW1lLlIucGF0Y2hWZXIxAKVOz0vDMBQ+m7/ieUvosmxMGYpCwdNg
qFSEQekhTbMazBJJ0tkh/u+atE5vO/guyft+vW9lGtlfQ8G8E0yr2nF3YDX3khWs4UEGtZPT
At3+fxCl9NSdM+zkXnllDSyuZheXBGVZdtr0bt2rMi0I+3YgKM+BLueLyXwG2fjmOYIPBHHU
Fp9zP9W2VYJrrKVpwwvec91JQgg4GTpncE8GdcLhhsK35fHhabXRYdQiGnmhI2l1c6e599GW
RZiHkEwhOFV3QfpjoBh1kR7+Q1zc75/X60G1tQ4bUAYM3yUzgb4sTVWVqorK5EnAT42/qccO
v8fHNkN6j+ATAfoCTtG/r/sBAAA=
--------------090203020600020104020707
Content-Type: application/x-gzip;
 name="datetime.R.patchVer2.gz"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="datetime.R.patchVer2.gz"

H4sICCXw90QCA2RhdGV0aW1lLlIucGF0Y2hWZXIyAKWOwUoDMRCGz+Ypxp4S0jQuVqSisOCp
UFRWBGHZQ7qbrsE0kSSt6YLvrtmIBxF6cC5J/vm+mSxNJ+MVVNy7lmu1dsId+Fp4ySveiSCD
2spZhW7+X4gxdmzPCXZyr7yyBs4XZ/MLgiilx6V3616V6aG1bweCyhLYZTGfLoCmoyigLBGk
Uht8KvxM2161QmMtTR9e8F7onSSEgJNh5wyOJNNjDtcMvpSH+8flsw7fbO63OjWt7m618D5p
NMVhGJ0QHI5TmITBGjn5UTKZiHzPA9P77mm1ytTGOmxAGTBiKxNOINa1aZpaNYkcnTH4a2r+
xe/9qReGzEcEHwjQJ/Ktnoj7AQAA
--------------090203020600020104020707--




More information about the R-devel mailing list