[Rd] print.POSIXct doesn't seem to use tz argument, as per its example

Dirk Eddelbuettel edd at debian.org
Fri Dec 16 13:00:19 CET 2016


On 16 December 2016 at 10:19, Martin Maechler wrote:
| >>>>> Jennifer Lyon <jennifer.s.lyon at gmail.com>
| >>>>>     on Thu, 15 Dec 2016 09:33:30 -0700 writes:
| 
| > On the documentation page for DateTimeClasses, in the Examples section,
| > there are the following two lines:
| > 
| > format(.leap.seconds)         # the leap seconds in your time zone
| > print(.leap.seconds, tz = "PST8PDT")  # and in Seattle's
| > 
| > The second line (using print) seems to ignore the tz argument, and prints
| > the dates in my time zone, while:
| > 
| > format(.leap.seconds, tz = "PST8PDT")
| > 
| > does print the dates in PST. The code in
| > https://github.com/wch/r-source/blob/trunk/src/library/base/R/datetime.R
| > around line 234 looks like the ... argument is passed to print, not to
| > format.
| > 
| > print.POSIXct <-
| > print.POSIXlt <- function(x, ...)
| > {
| >     max.print <- getOption("max.print", 9999L)
| >     if(max.print < length(x)) {
| >         print(format(x[seq_len(max.print)], usetz = TRUE), ...)
| >         cat(' [ reached getOption("max.print") -- omitted',
| >             length(x) - max.print, 'entries ]\n')
| >     } else print(if(length(x)) format(x, usetz = TRUE)
| >                  else paste(class(x)[1L], "of length 0"), ...)
| >     invisible(x)
| > }
| > 
| > The documentation for print() on this page seems to be silent on tz as an
| > argument, but I do believe the example using print() does not work as
| > advertised.
| 
| > Thanks.
| > 
| > Jen
| 
| Thank you, Jen!
| Indeed,  both your observation and your diagnosis are correct:
| This has been a misleading example and needs amending (or the
| code is changed, see below).
| 
| The most simple fix would be to replace  'print('  by
| 'format('; then the example would work as advertized.
| That change has two drawbacks still:
| 
| 1) format(.) examples on the help of print.POSIXct() where
|    format.POSIXct() is *not* documented 
| 
| 2) It *would* make sense that print.POSIXct() allowed for a 'tz' argument
|    (and maybe 'usetz' too).  This/these would be (an) extra
|    argument(s) rather than passing '...' not just to print() but
|    also to format()rathere
| 
| My personal preference would tend to add both
|      tz = ""
| and  usetz = TRUE
| to the formal arguments of print.POSIXct and pass them to the
| format(.) calls.

I think that is a good idea. I have been by this a few times too.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org



More information about the R-devel mailing list