From edd at debian.org  Fri Dec 16 13:00:19 2016
From: edd at debian.org (Dirk Eddelbuettel)
Date: Fri, 16 Dec 2016 06:00:19 -0600
Subject: [Rd] print.POSIXct doesn't seem to use tz argument,
	as per its example
In-Reply-To: <22611.45452.303730.470838@stat.math.ethz.ch>
References: <CAKstpn7h88=OUpNjV6ZKCEbivWTZfAqhEDAzj01wodBYdcJThQ@mail.gmail.com>
	<22611.45452.303730.470838@stat.math.ethz.ch>
Message-ID: <22611.55123.728240.315623@max.nulle.part>


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



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