From Thomas.Mang at fiwi.at  Mon Nov 24 10:02:20 2008
From: Thomas.Mang at fiwi.at (Thomas Mang)
Date: Mon, 24 Nov 2008 10:02:20 +0100
Subject: [Rd] timezone attribute lost
Message-ID: <ggdqj2$334$1@ger.gmane.org>

Hi,

As I didn't get any response on the general help list and I don't know 
if there is a bug in action I am trying my luck here.

I was highly surprised to find out that during simple operations (see 
code below) the timezone attribute for POSIXct data is lost and then, 
upon the next interpretation, the system settings are used (which are 
plain wrong in my case).

I have used R 2.8.0 under Windows XP with the system timezone (managed 
by Windows) set to CET - I suppose however that all other timezones, 
with the exception of GMT, will show similiar surprising behavior (and 
those who live in GMT-zone: If you change your timezone setting please 
restart R, otherwise the effect won't take place).


# input data
# note that the timezone is deliberately set to GMT, and of course I 
want the operations below to take place in GMT-time
Time = as.POSIXct(strptime(c("2007-12-12 14:30:15", "2008-04-14 
15:31:34", "2008-04-14 15:31:34"), format = "%Y-%m-%d %H:%M:%S", tz = 
"GMT"))
Time  # OK, time zone is GMT
attr(Time, "tzone")  # OK, time zone is GMT


# Surprise 1:
TApply = tapply(1:3, Time, max)
names(TApply) # wrong, names are converted to time zone of system

# Surprise 2:
UTime = unique(Time)
UTime  # wrong, again time zone of system is used
attr(UTime, "tzone")  # == NULL


I know how to "solve" the problem (for example by setting an R system 
variable TZ to GMT), but I wonder why is this mess happening at all? 
Moreover, is this behavior considered to be a feature, or a plain bug ?

Thanks,
Thomas



[Rd] timezone attribute lost
Thomas Mang