From @|mon@urb@nek @end|ng |rom R-project@org  Thu Nov  3 08:28:57 2022
From: @|mon@urb@nek @end|ng |rom R-project@org (Simon Urbanek)
Date: Thu, 3 Nov 2022 20:28:57 +1300
Subject: [Rd] as.Date without "origin"
In-Reply-To: <UVIu3zmRKG3oM__PzasW3vvKTYxIrBpYeoHDaghpllF9-_HuAAPEmQbDweRrMj3_KrKDjbmOI5EySuBKOt_0vQsOJRLcmO7w20rqi5MSo6I=@protonmail.com>
References: <EKNZOOr0Xk-P1uT_HZiKSmlTniaWJ9qxbkQAdiT-WTIadalBDTvhObEvUFCj_yZEXiO1_mImOaOMtS-gxB3Rc5rcCUyeUZY9KTpuq-Yd89U=@protonmail.com>
 <345b7101-f116-e6aa-b8cf-522f68ed5638@prodsyse.com>
 <UVIu3zmRKG3oM__PzasW3vvKTYxIrBpYeoHDaghpllF9-_HuAAPEmQbDweRrMj3_KrKDjbmOI5EySuBKOt_0vQsOJRLcmO7w20rqi5MSo6I=@protonmail.com>
Message-ID: <C95D613E-8B9A-4878-BB29-23D1479CF5A5@R-project.org>

Dan,

as.Date() and as.POSIXct() have been updated to allow replacement of the hidden functions .POSIXct() and .Date() which were the only way to correctly convert the numeric representation of the objects as Johannes explained. Given that this is a very common operation (especially with POSIXct) it makes sense to not rely on hidden functions and will allow us to possibly deprecate them. And as Peter pointed out, this is R-devel so manuals won't be necessarily updated until the full functionality is implemented and this is part of a larger overhaul of the date/time functions which has not been finished yet.

Cheers,
Simon



> On Nov 3, 2022, at 2:38 AM, Dan Dalthorp via R-devel <r-devel at r-project.org> wrote:
> 
> I don't see a compelling rationale for changing the default behavior as.Date to deviate from the wholly reasonable status quo of "as.Date will accept numeric data (the number of days since an epoch), but only if origin is supplied." That has been the expectation for a long, long time. 
> 
> In any case, the manual should match the behavior.
> 
> -DHD
> 
> 
> 
> 
> ------- Original Message -------
> On Wednesday, November 2nd, 2022 at 6:20 AM, Spencer Graves <spencer.graves at prodsyse.com> wrote:
> 
> 
>> 
>> 
>> I've felt that "as.Date" should default to origin "1970-01-01", so I
>> added a modification to Ecfun:
>> 
>> 
>> Ecfun::as.Date1970(0)
>> 
>> 
>> If R-devel chose to change the default on this, I would happily
>> deprecate Ecfun::as.Date1970 in favor of base::as.Date ;-)
>> 
>> 
>> I would therefore support changing the documentation to match the new
>> behavior.
>> 
>> 
>> Spencer Graves
>> 
>> 
>> On 11/2/22 7:30 AM, Dan Dalthorp via R-devel wrote:
>> 
>>> The new (2022-10-11 r83083 ucrt) as.Date function returns a date rather than an error when called without "origin" specified.
>>> 
>>> # previous versions of R
>>> as.Date(0)
>>> # Error in as.Date.numeric(0) : 'origin' must be supplied
>>> 
>>> # new:
>>> as.Date(0)
>>> # [1] "1970-01-01"
>>> 
>>> This is at odds with the help file, which gives:
>>> 
>>> origin
>>> 
>>> aDateobject, or something which can be coerced byas.Date(origin, ...)to such an object.
>>> 
>>> And:
>>> as.Datewill accept numeric data (the number of days since an epoch), butonlyiforiginis supplied.
>>> 
>>> The behavior described in the help file and implemented in previous versions seems more reasonable than returning a date with an arbitrary "origin". In any case, in the r-devel there is a mismatch between the function and its description.
>>> 
>>> -Dan
>>> [[alternative HTML version deleted]]
>>> 
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] as.Date without "origin"
Simon Urbanek