[Rd] base::as.Date inconsistency/bug
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 9 11:00:42 CET 2010
Well, 2.11.0 is overdue for an update: see the posting guide.
You've confused the printed representation with the object. If there
is an issue, it is in the formatting (and hence printing) of
fractional dates before the epoch ("1970-01-01 00:00"). As the help
page says
It is intended that the date should be an integer, but this is not
enforced in the internal representation. Fractional days will be
ignored when printing.
and you've fallen foul of ignoring that warning. I think it does
actually work as documented, but it might confuse
non-readers-of-help-pages less if it always rounded to the previous
midnight, and R-patched now does that.
For your obsolete version of R, simply heed the warning and do not use
fractional days.
On Mon, 8 Nov 2010, Andreas Eckner wrote:
> Dear all,
>
> I would like point out a potential bug (or at least inconsistency) in the
> way the R base package converts numeric numbers to dates. Specifically,
> consider the following two calls:
>
>> as.Date(0.5, origin="1969-12-31")
> [1] "1970-01-01"
>> as.Date(0.5, origin="1970-01-01")
> [1] "1970-01-01"
>
> As you can see, both calls produce the same output on the screen. Curiously,
> the output is NOT the same for other consecutive origins:
>
>> as.Date(0.5, origin="2009-12-31")
> [1] "2009-12-31"
>> as.Date(0.5, origin="2010-01-01")
> [1] "2010-01-01"
>
> Best regards,
> Andreas Eckner
>
>
> ----------------------
>> sessionInfo()
> R version 2.11.0 (2010-04-22)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list