Andrew Piskorski
2023-Oct-24 04:01 UTC
[Rd] as.character.Date() strips names in R 4.3.2 beta, bug?
In previous versions of R, as.character.Date() retained any names on its input vector. In R 4.3.2 beta, it removes names. Is this change intentional, or a bug? (For what it's worth, I greatly dislike this change, and hope it gets changed back.) $ grep DESCRIPTION /etc/lsb-release DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS" $ R --vanilla R version 4.2.1 Patched (2022-07-09 r82577) -- "Funny-Looking Kid"> v2 <- structure(as.Date(c('2021-10-06','2021-10-08')) ,names=c('a','b')) > v2a b "2021-10-06" "2021-10-08"> class(v2)[1] "Date"> as.character(v2)a b "2021-10-06" "2021-10-08"> as.character.Date(v2)a b "2021-10-06" "2021-10-08" $ grep DESCRIPTION /etc/lsb-release DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS" $ R --vanilla R version 4.3.2 beta (2023-10-22 r85392) -- "Eye Holes"> v2 <- structure(as.Date(c('2021-10-06','2021-10-08')) ,names=c('a','b')) > v2a b "2021-10-06" "2021-10-08"> class(v2)[1] "Date"> as.character(v2)[1] "2021-10-06" "2021-10-08"> as.character.Date(v2)[1] "2021-10-06" "2021-10-08" -- Andrew Piskorski <atp at piskorski.com>
Martin Maechler
2023-Oct-24 08:53 UTC
[Rd] as.character.Date() strips names in R 4.3.2 beta, bug?
>>>>> Andrew Piskorski >>>>> on Tue, 24 Oct 2023 00:01:58 -0400 writes:> In previous versions of R, Not in R 4.3.0 or 4.3.1 {you are a bit late with updating ..}. > as.character.Date() retained any names on > its input vector. In R 4.3.2 beta, it removes names. Is this change > intentional, or a bug? (For what it's worth, I greatly dislike this > change, and hope it gets changed back.) Yes, this change has been *very* intentional: as.character() for these objects since 4.3.0 (April 2023) finally behaves as other as.character() methods and *does* drop attributes. The NEWS entry (visible since more than a year if you'd follows NEWS.Rd tweats/.. etc) is ? ?as.character(<POSIXt>)? now behaves more in line with the methods for atomic vectors such as numbers, and is no longer influenced by ?options()?. Ditto for ?as.character(<Date>)?. The ?as.character()? method gets arguments ?digits? and ?OutDec? with defaults _not_ depending on ?options()?. Use of ?as.character(*, format = .)? now warns. At the time (Sep 2022!) there was quite some traffic on R-devel about this, IIRC. Often it's most convenient for people to use format() instead of as.character() if they want to keep names, notably here, because before the fix, the as.character() method for Date and POSIXt *was* identical to format() --- contrary to all other methods for "simple" vectors. There's more about this if just simply at ?as.character.Date Best regards, Martin -- Martin Maechler ETH Zurich and R Core team