Dear list,<div><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><br></div><div>For example:</div><div><br></div><div><div>> require(data.table)</div><div>Loading required package: data.table</div><div><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><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><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><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><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><br></div><div>Best regards,</div><div>+ Nicolas Chapados</div><div><br></div>