<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.17080" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010>Nicolas, </SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010>That's not really a data.table issue. It's generally a
problem with POSIXct. See here:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010></SPAN></FONT> </DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010>> x = seq(as.POSIXct("2010-01-01", "GMT"),
as.POSIXct("2010-01-10", "GMT"), length.out=2)<BR>> <BR>> c(x,x)<BR>[1]
"2009-12-31 19:00:00 EST" "2010-01-09 19:00:00 EST"<BR>[3] "2009-12-31 19:00:00
EST" "2010-01-09 19:00:00 EST"<BR></SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010>To get around this, I generally fix the timezone for
the system as follows:</SPAN></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Arial size=2><SPAN
class=012315601-01092010> <BR>> Sys.setenv(TZ="GMT") # time zones drive
me crazy!<BR>> <BR>> c(x,x)<BR>[1] "2010-01-01 GMT" "2010-01-10 GMT"
"2010-01-01 GMT" "2010-01-10 GMT"<BR></DIV></SPAN></FONT>
<DIV><FONT face=Arial size=2><SPAN class=012315601-01092010>Also, if you just
have dates, it's better to stick with the Date class (or chron). In the
development version of data.table, we also have integer date and time classes
that work well with data.table (faster sorting and
grouping).</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=012315601-01092010></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=012315601-01092010>-
Tom</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV><FONT face=Arial
size=2></FONT><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B>
datatable-help-bounces@lists.r-forge.r-project.org
[mailto:datatable-help-bounces@lists.r-forge.r-project.org] <B>On Behalf Of
</B>Nicolas Chapados<BR><B>Sent:</B> Tuesday, August 31, 2010
15:40<BR><B>To:</B>
datatable-help@lists.r-forge.r-project.org<BR><B>Subject:</B> [datatable-help]
Automagic timezone convertion on data.table rbind<BR></FONT><BR></DIV>
<DIV></DIV>Dear list,
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>I'm using a data.table that contains date columns (in POSIXct format).
There appears to be an issue with automatic timezone conversion when
rbinding from NULL (or an empty data.table), as would occur when one is
progressively building up the table in a loop.</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>For example:</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>
<DIV>> require(data.table)</DIV>
<DIV>Loading required package: data.table</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>## Currently located in the North-America Eastern Standard Time
zone.</DIV>
<DIV>> Sys.timezone()</DIV>
<DIV>[1] "America/Montreal"</DIV>
<DIV>> a <- NULL</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>## Create a table with a single date column (GMT timezone)</DIV>
<DIV>> b <- data.table(x = seq(as.POSIXct("2010-01-01", "GMT"),
as.POSIXct("2010-01-10", "GMT"), length.out=10))</DIV>
<DIV>> b</DIV>
<DIV> x</DIV>
<DIV> [1,] 2010-01-01</DIV>
<DIV> [2,] 2010-01-02</DIV>
<DIV> [3,] 2010-01-03</DIV>
<DIV> [4,] 2010-01-04</DIV>
<DIV> [5,] 2010-01-05</DIV>
<DIV> [6,] 2010-01-06</DIV>
<DIV> [7,] 2010-01-07</DIV>
<DIV> [8,] 2010-01-08</DIV>
<DIV> [9,] 2010-01-09</DIV>
<DIV>[10,] 2010-01-10</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>## Bind it from NULL: Oops! The timezone changes to EST!</DIV>
<DIV>> rbind(a,b)</DIV>
<DIV>
x</DIV>
<DIV> [1,] 2009-12-31 19:00:00</DIV>
<DIV> [2,] 2010-01-01 19:00:00</DIV>
<DIV> [3,] 2010-01-02 19:00:00</DIV>
<DIV> [4,] 2010-01-03 19:00:00</DIV>
<DIV> [5,] 2010-01-04 19:00:00</DIV>
<DIV> [6,] 2010-01-05 19:00:00</DIV>
<DIV> [7,] 2010-01-06 19:00:00</DIV>
<DIV> [8,] 2010-01-07 19:00:00</DIV>
<DIV> [9,] 2010-01-08 19:00:00</DIV>
<DIV>[10,] 2010-01-09 19:00:00</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>## Same behavior from an empty data table.</DIV>
<DIV>> rbind(data.table(), b)</DIV>
<DIV>
x</DIV>
<DIV> [1,] 2009-12-31 19:00:00</DIV>
<DIV> [2,] 2010-01-01 19:00:00</DIV>
<DIV> [3,] 2010-01-02 19:00:00</DIV>
<DIV> [4,] 2010-01-03 19:00:00</DIV>
<DIV> [5,] 2010-01-04 19:00:00</DIV>
<DIV> [6,] 2010-01-05 19:00:00</DIV>
<DIV> [7,] 2010-01-06 19:00:00</DIV>
<DIV> [8,] 2010-01-07 19:00:00</DIV>
<DIV> [9,] 2010-01-08 19:00:00</DIV>
<DIV>[10,] 2010-01-09 19:00:00</DIV></DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>This behavior is somewhat puzzling. Any pointers as to how to
preserve timezone information would be greatly appreciated! For the
record, I'm with R version 2.9.2 and time.date version 1.4.1 (the latest
on CRAN).</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>Best regards,</DIV>
<DIV>+ Nicolas Chapados</DIV>
<DIV><BR></DIV></BLOCKQUOTE></BODY></HTML>