Skip to content

c(a, b) for POSIXct objects with tzone attributes?

4 messages · Spencer Graves, Bert Gunter, Brian Ripley

#
Hello:


       What is the recommended method for retaining the tzone attributes 
when concatonating POSIXct objects?
[1] "1970-01-01 12:00:00 GMT"
the time zone of the operating system
[1] "1970-01-01 04:00:00 PST" "1970-01-01 04:00:00 PST"
[1] "1970-01-01 12:00:00 GMT" "1970-01-01 12:00:00 GMT"


       "c" is a generic function with a method defined for objects of 
class POSIXct, so the results here were what is returned by c.POSIXct 
[as discussed with help('c.POSIXct')].


       Is there some other function like "c2", say, that tries to retain 
attributes where "c" strips all but names?


       Thanks,
       Spencer
#
On 09/07/2012 07:12, Bert Gunter wrote:
Actually, impossible as the design allows for only one timezone for each 
object.
We considered having c() retain the timezone if it was common to all the 
objects, but the main issue was that c() was documented to remove 
attributes:

      ?c? is sometimes used for its side effect of removing attributes
      except names, for example to turn an array into a vector.
      ?as.vector? is a more intuitive way to do this, but also drops
      names.  Note too that methods other than the default are not
      required to do this (and they will almost certainly preserve a
      class attribute).

So, sometimes removing and sometimes retaining attributes was going to 
be confusing.

But in any case, the documentation (?c.POSIXct) is clear:

      Using ?c? on ?"POSIXlt"? objects converts them to the current time
      zone, and on ?"POSIXct"? objects drops any ?"tzone"? attributes
      (even if they are all marked with the same time zone).

So the recommended way is to add a "tzone" attribute if you know what 
you want it to be.  POSIXct objects are absolute times: the timezone 
merely affects how they are converted (including to character for printing).

  
    
2 days later
#
Hi, Prof. Ripley, Bert:


       Thanks for the comments.


       Might there be a function similar to "c" but retains more 
attributes than just names?


       Before I write such, I felt a need to ask if anyone knows where 
it may already have been done -- and if people have suggestions for how 
they think it should function with particular classes of objects?  For 
example, if create an S3 generic "c2" for this, "c2.default" might 
retains all the attributes that make sense from the first argument and 
ignore attributes from later arguments if it makes sense to do so.  This 
would then retain the tzone attribute from the first of multiple POSIXct 
arguments.


       Thanks,
       Spencer
On 7/9/2012 6:24 AM, Prof Brian Ripley wrote: