Re: [Rd] as.Date without "origin"
On 11/2/22 5:32 PM, Rui Barradas wrote: Às 20:47 de 02/11/2022, Johannes Rauh escreveu: Dear all, I would throw in my vote to have origin = "1970-01-01" as a default in as.Date(). Why? Well, in fact, the "converse" function as.numeric() does have an implicit default: as.numeric(Sys.Date()) [1] 19298 In fact, as.numeric seems to not even have a method for class "Date", and so as.numeric() does not even have an argument "origin" or the like. In any case, when using Date objects, it may happen that the result is of clas numeric. For example: ifelse(TRUE, Sys.Date(), Sys.Date() + 1) [1] 19298 So, in order to transform the result back to class "Date" using as.Date(), I always need to remember the universal default origin 1970-01-01 and I need to write it out explicitly. I find that rather inconvenient, and so having the default origin as a default would make very much sense to me here. Of course, for that particular example, it would also help me if ifelse() would properly handle Date vectors. Best Johannes Gesendet: Mittwoch, 02. November 2022 um 14:38 Uhr Von: "Dan Dalthorp via R-devel" An: "Spencer Graves" Cc: "r-devel@r-project.org" Betreff: Re: [Rd] as.Date without "origin" 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 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel Hello, ifelse does properly handle Date objects. From its documentation: Usage ifelse(test, yes, no) [...] Value A vector of the same length and attributes (including dimensions and "class") as test and data values from the values of yes or no. In your example test = TRUE and yes = Sys.Date() so the return value is class(ifelse(TRUE, Sys.Date(), Sys.Date() + 1)) # [1] "numeric" class(ifelse(TRUE, Sys.Date(), Sys.Date() + 1L)) # [1] "numeric" This is expected behavior. I was expecting class "integer", not "numeric" but this too is documented in ?Dates section Details 2nd paragraph. 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. It is possible to produce fractional days via the mean method or by adding or subtracting (see Ops.Date). I routinely use fractional days with class "Date". I hope I can continue to do so. Thanks, Spencer Graves Hope this helps, Rui Barradas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
Às 20:47 de 02/11/2022, Johannes Rauh escreveu: Dear all, I would throw in my vote to have origin = "1970-01-01" as a default in as.Date(). Why? Well, in fact, the "converse" function as.numeric() does have an implicit default: as.numeric(Sys.Date()) [1] 19298 In fact, as.numeric seems to not even have a method for class "Date", and so as.numeric() does not even have an argument "origin" or the like. In any case, when using Date objects, it may happen that the result is of clas numeric. For example: ifelse(TRUE, Sys.Date(), Sys.Date() + 1) [1] 19298 So, in order to transform the result back to class "Date" using as.Date(), I always need to remember the universal default origin 1970-01-01 and I need to write it out explicitly. I find that rather inconvenient, and so having the default origin as a default would make very much sense to me here. Of course, for that particular example, it would also help me if ifelse() would properly handle Date vectors. Best Johannes Gesendet: Mittwoch, 02. November 2022 um 14:38 Uhr Von: "Dan Dalthorp via R-devel" An: "Spencer Graves" Cc: "r-devel@r-project.org" Betreff: Re: [Rd] as.Date without "origin" 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 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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel Hello, ifelse does properly handle Date objects. From its documentation: Usage ifelse(test, yes, no) [...] Value A vector of the same length and attributes (including dimensions and "class") as test and data values from the values of yes or no. In your example test = TRUE and yes = Sys.Date() so the return value is class(ifelse(TRUE, Sys.Date(), Sys.Date() + 1)) # [1] "numeric" class(ifelse(TRUE, Sys.Date(), Sys.Date() + 1L)) # [1] "numeric" This is expected behavior. I was expecting class "integer", not "numeric" but this too is documented in ?Dates section Details 2nd paragraph. 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. It is possible to produce fractional days via the mean method or by adding or subtracting (see Ops.Date). Hope this helps, Rui Barradas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
Dear all, I would throw in my vote to have origin = "1970-01-01" as a default in as.Date(). Why? Well, in fact, the "converse" function as.numeric() does have an implicit default: > as.numeric(Sys.Date()) [1] 19298 In fact, as.numeric seems to not even have a method for class "Date", and so as.numeric() does not even have an argument "origin" or the like. In any case, when using Date objects, it may happen that the result is of clas numeric. For example: > ifelse(TRUE, Sys.Date(), Sys.Date() + 1) [1] 19298 So, in order to transform the result back to class "Date" using as.Date(), I always need to remember the universal default origin 1970-01-01 and I need to write it out explicitly. I find that rather inconvenient, and so having the default origin as a default would make very much sense to me here. Of course, for that particular example, it would also help me if ifelse() would properly handle Date vectors. Best Johannes > Gesendet: Mittwoch, 02. November 2022 um 14:38 Uhr > Von: "Dan Dalthorp via R-devel" > An: "Spencer Graves" > Cc: "r-devel@r-project.org" > Betreff: Re: [Rd] as.Date without "origin" > > 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 > 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@r-project.org mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-devel > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
Of course. But the broken as.Date in R-devel breaks one of my packages, so I'm getting threats of the package being removed from CRAN in a few days if the breakage is not resolved. DHD --- Original Message --- On Wednesday, November 2nd, 2022 at 8:30 AM, peter dalgaard wrote: > > > This is in R-devel, mind you, i.e., unreleased and quite possibly unfinished > work. > > No released version of R does this. E.g., > > > as.Date(0) > > Error in as.Date.numeric(0) : 'origin' must be supplied > > > version > > _ > platform x86_64-apple-darwin21.6.0 > arch x86_64 > os darwin21.6.0 > system x86_64, darwin21.6.0 > status Patched > major 4 > minor 2.2 > year 2022 > month 11 > day 02 > svn rev 83236 > language R > version.string R version 4.2.2 Patched (2022-11-02 r83236) > nickname Innocent and Trusting > > > On 2 Nov 2022, at 14:38 , Dan Dalthorp via R-devel r-devel@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.gra...@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@r-project.org mailing list > > > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Office: A 4.23 > Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
This is in R-devel, mind you, i.e., unreleased and quite possibly unfinished work. No released version of R does this. E.g., > as.Date(0) Error in as.Date.numeric(0) : 'origin' must be supplied > version _ platform x86_64-apple-darwin21.6.0 arch x86_64 os darwin21.6.0 system x86_64, darwin21.6.0 status Patched major 4 minor 2.2 year 2022 month 11 day02 svn rev83236 language R version.string R version 4.2.2 Patched (2022-11-02 r83236) nickname Innocent and Trusting > On 2 Nov 2022, at 14:38 , Dan Dalthorp via R-devel > 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 > 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@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-devel > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
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 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@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date without "origin"
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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] as.Date without "origin"
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@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel