From pgilbert at bank-banque-canada.ca  Thu Aug 19 16:16:37 2010
From: pgilbert at bank-banque-canada.ca (Paul Gilbert)
Date: Thu, 19 Aug 2010 10:16:37 -0400
Subject: [Rd] c.POSIXct
In-Reply-To: <AANLkTin=8k4UfBqzjQmHa9ntQP3V9zhuhsfkL_qzZyWi@mail.gmail.com>
References: <AANLkTinGcXRQd5+Xmo2ad5HoofdbzhZbEaSznAgCL3vO@mail.gmail.com>
	<AANLkTin=8k4UfBqzjQmHa9ntQP3V9zhuhsfkL_qzZyWi@mail.gmail.com>
Message-ID: <D611103AA7EE3B4DAE7F7D49C72B291A02C7E497@EXMAIL2.bocad.bank-banque-canada.ca>

I used to get caught by this c() behaviour often, but now I do expect it to drop attributes. I think it would break many things if you change it, and force people to write different code when they really do want to drop attributes. When you want new behaviour it is usually better to define a new function, ca() maybe?

Paul

>-----Original Message-----
>From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-
>project.org] On Behalf Of Gabor Grothendieck
>Sent: August 18, 2010 6:23 PM
>To: r-devel at r-project.org
>Subject: Re: [Rd] c.POSIXct
>
>No one answered this so I submitted it to the bugs system and there I
>got the response that it is documented behavior; however, whether its
>documented or not is hardly the point -- its undesirable that tzone is
>lost when using c.
>
>On Thu, Aug 12, 2010 at 11:33 AM, Gabor Grothendieck
><ggrothendieck at gmail.com> wrote:
>> Currently if x1 and x2 are POSIXct then c(x1, x2) will not have a
>> tzone attribute even if x1 or x2 or both do but it should.
>>
>> This could be fixed with the following c.POSIXct:
>>
>> c.POSIXct <- function (..., recursive = FALSE) {
>> ? ? ? ?tzones <- lapply(list(...), attr, which = "tzone")
>> ? ? ? ?lengths <- sapply(tzones, length)
>> ? ? ? ?if (any(lengths > 1)) stop("tzone cannot have length greater
>than 1")
>> ? ? ? ?which <- sapply(tzones, length) == 1
>> ? ? ? ?tzone <- unique(unlist(tzones[which]))
>> ? ? ? ?if (length(tzone) != 1) tzone <- NULL
>> structure(c(unlist(lapply(list(...), unclass))), class = c("POSIXt",
>> ? ?"POSIXct"), tzone = tzone)
>> }
>>
>> # test
>> x1 <- Sys.time()
>> x2 <- structure(x1, tzone = "UTC")
>> x3 <- structure(x1, tzone = "other")
>>
>> # these all currently give NULL but with
>> # above give indicated value
>>
>> attr(c(x1, x1), "tzone") # NULL
>> attr(c(x2, x2), "tzone") # "UTC"
>> attr(c(x1, x2), "tzone") # "UTC"
>> attr(c(x2, x1), "tzone") # "UTC"
>> attr(c(x1, x2, x3), "tzone") # NULL
>>
>
>______________________________________________
>R-devel at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-devel
====================================================================================

La version fran?aise suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential in...{{dropped:26}}



[Rd] c.POSIXct
Paul Gilbert