[Rd] proposed change to [.POSIXct

Whit Armstrong Whit.Armstrong at tudor.com
Thu Aug 19 17:11:44 CEST 2004


R developers,

The "tzone" attribute is stripped from a POSIXct object when the subscript
command is called ("[.POISXct").  This results in dates being printed in the
locale specific format after a subscript operation is applied to a POSIXct
object which has cause several problems for me in the past.

Here is an example of this problem under R 1.9.1:

> x <- ISOdate(rep(2000,2),rep(3,2),rep(26,2),hour=0)
> x
[1] "2000-03-26 GMT" "2000-03-26 GMT"
> x[1]
[1] "2000-03-25 19:00:00 Eastern Standard Time"
> 
> unclass(x)
[1] 954028800 954028800
attr(,"tzone")
[1] "GMT"
> unclass(x[1])
[1] 954028800
>

Here is the current code for "[.POSIXct"

> get("[.POSIXct")
function (x, ..., drop = TRUE) 
{
    cl <- oldClass(x)
    class(x) <- NULL
    val <- NextMethod("[")
    class(val) <- cl
    val
}
<environment: namespace:base>
> 

I believe a sensible change is the following:

"[.POSIXct" <-
function (x, ..., drop = TRUE) 
{
    at <- attributes(x)
    class(x) <- NULL
    val <- NextMethod("[")
    attributes(val) <- at
    val
}

Using this code, the "tzone" attribute is preserved allowing dates to
continue to be printed in their intended timezone.

Thank you for considering this issue.

Regards,
Whit Armstrong

Here are the details of my system:

> R.Version()
$platform
[1] "i386-pc-mingw32"

$arch
[1] "i386"

$os
[1] "mingw32"

$system
[1] "i386, mingw32"

$status
[1] ""

$major
[1] "1"

$minor
[1] "9.1"

$year
[1] "2004"

$month
[1] "06"

$day
[1] "21"

$language
[1] "R"

> 

	[[alternative HTML version deleted]]



More information about the R-devel mailing list