Skip to content
Prev 37387 / 63424 Next

c.POSIXct

I'm with Gabor on this.  I naively would not expect c() to strip 
attributes generally, and I've been surprise more than once to find the 
time zone attribute stripped when I did not expect that.


       Might it make sense to add an argument like 
"keepAttributes=FALSE" to the "c" function?  Then people like Gabor and 
me would know that we would have to specify "keepAttributes = TRUE" if 
we wanted attributes to be kept.  Having this in the documentation would 
also help advertise the default behavior.  I would expect that 
attributes like "dim" and "dimnames" should always be dropped, 
regardless of the value of "keepAttributes".  With "keepAttributes = 
TRUE", "names" would be concatenated, and other attributes would be 
taken from the first argument with other attributes of later arguments 
ignored.


QUESTIONS:


       1.  With POSIXct, isn't the numeric part always in GMT, 
regardless of time zone?  Then the "tzone" attribute only affects the 
display?  Consider the following:


 > (z <- Sys.time())
[1] "2010-08-18 21:16:38 PDT"
 > as.numeric(z)
[1] 1282191399
 > attr(z, 'tzone') <- 'GMT'
 > as.numeric(z)
[1] 1282191399
 > z
[1] "2010-08-19 04:16:38 GMT"


       2.  How can one specify a time zone other than "GMT" and the 
default local time zone?

 > attr(z, 'tzone') <- Sys.timezone()
 > z
[1] "2010-08-19 04:16:38 GMT"
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'PDT'


       Thanks,
       Spencer Graves
On 8/18/2010 7:53 PM, Gabor Grothendieck wrote: