From ripley at stats.ox.ac.uk  Thu Aug 19 17:49:54 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Thu Aug 19 17:49:57 2004
Subject: [Rd] proposed change to [.POSIXct
In-Reply-To: <7669F018DC9DD711AEC500065B3D5ABF02CAD1C1@tudor.com>
Message-ID: <Pine.LNX.4.44.0408191642260.24765-100000@gannet.stats>

Sorry, but you really do not want that the change your patch makes.
Copying across the attributes will for example copy the original names,
any dim's etc.  There is a very good reason why [ does not do that itself.

I am not even sure you want to preserve the "tzone" attribute.  A POSIXct
time is an absolute time, and that attribute is just a reminder of where
it came from.  Since you have operated on it, the history is broken.

As timezones are always used when printing, I don't see anything
problematic about your example.  Do you have a more convincing example
from `which has cause several problems for me in the past'?

On Thu, 19 Aug 2004, Whit Armstrong wrote:

> 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]]
> 
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] proposed change to [.POSIXct
Prof Brian Ripley