[R] lubridate concatenation issue

Peter Ehlers ehlers at ucalgary.ca
Fri Nov 16 08:08:27 CET 2012


On 2012-11-15 18:36, Andre Zege wrote:
> I took a look at Hadley's lubridate which seems a very neat package, but i am having a small problem with  concatenating lubridates to build vectors of it. Namely when function c( )  is applied to lubridate seems to change time to a local timezone in this particular case changing the date to previous one.
>
>> d<-ymd('20111231')
>> d
> [1] "2011-12-31 UTC"
>> c(d)
> [1] "2011-12-30 19:00:00 EST"
>
>
>
> Is this the expected behavior and if yes, how could it be avoided for this function and the others that possibly do the same? I mean, i could create the date in my local timezone and avoid this, but if i don't do it, is there an option in environment or functions to avoid this from happening -- otherwise i need to watch out for nasty bugs.
>
>
> Thanks
> Andre

It is expected. Look at

  attributes(d)

and

  attributes(c(d))

You'll see that c() removes the 'tzone' attribute.
This is mentioned on the help page for POSIXct.
The only way I know to 'fix' this is to reassign the
attribute:

  e <- c(d)
  attr(e, "tzone") <- "UTC"

But there might a better solution to whatever the real problem is.

Peter Ehlers




More information about the R-help mailing list