[R] time zone problems

Marc Fischer mlfischer at lbl.gov
Wed Apr 4 07:06:12 CEST 2007


Folks,

I'm having  trouble with how datetime objects with time zones are set 
and plotted.   This may be the result of my running R (2.4.0) on a 
Windoze XP box.  Perhaps not.  Here are two example problems I need 
advise on if you have time:

1)  I collect data with dates (often as a fractional day of year) in 
UTC.  Using strptime to create date time objects appears to force the 
data into the local time zone (including daylight time) of my 
machine.  Setting the tz="UTC" or "GMT" inside strptime seems to be 
ignored.  I made the following cumbersome work around:

foo$date=strptime((paste(yr,DOY), 0, 0), format="%Y %j %H %M",tz="") + 0
tzone.err=as.numeric(as.POSIXct(format(Sys.time(),tz="GMT"))-as.POSIXct(format(Sys.time(),tz="")))*3600
foo$date=foo$date-tzone.err
attributes(foo$date)$tzone="GMT"

Am I missing something obvious or is this a problem with Windoze?

2) Once I have the data in GMT, I try to plot it using the standard 
plot command but it converts the data back to local time before 
making the plot.  Now the work around is:

plot(foo$date+tzone.err,foo$var, xlab="Date(GMT)")

  Very frustrating... I've read the help pages but can't find answers 
to these issues.  Any help?

Best regards,

Marc



More information about the R-help mailing list