Davis Vaughan
2021-Sep-13 20:35 UTC
[Rd] formatC(character()) returns length 1 result, but is documented otherwise
Hi all, I believe I have either found a small bug, or a possible inconsistency in documentation. formatC() returns a length 1 result if given a length 0 character() as input. formatC(character()) #> [1] "" But the return value documentation states that it returns: "A character object of same size and attributes as x". I'd love for this to return a size 0 result here, consistent with the docs and my mental model of size stability for this function. Here is where this happens (it is explicitly hard coded): https://github.com/wch/r-source/blob/79298c499218846d14500255efd622b5021c10ec/src/library/base/R/format.R#L149 Thanks, Davis Vaughan [[alternative HTML version deleted]]
Martin Maechler
2021-Sep-22 10:46 UTC
[Rd] formatC(character()) returns length 1 result, but is documented otherwise
>>>>> Davis Vaughan >>>>> on Mon, 13 Sep 2021 16:35:47 -0400 writes:> Hi all, > I believe I have either found a small bug, or a possible inconsistency in > documentation. formatC() returns a length 1 result if given a length 0 > character() as input. > formatC(character()) > #> [1] "" > But the return value documentation states that it returns: "A character > object of same size and attributes as x". > I'd love for this to return a size 0 result here, consistent with the docs > and my mental model of size stability for this function. > Here is where this happens (it is explicitly hard coded): > https://github.com/wch/r-source/blob/79298c499218846d14500255efd622b5021c10ec/src/library/base/R/format.R#L149 > Thanks, > Davis Vaughan > [[alternative HTML version deleted]] This may well be a "historical artefact" - definitely older than R 1.0.0. ... and yes I've known much less about S and its new dialect R, back in 1998. ;-) You are right in all you say, and my mental model corresponds to yours, so we will almost surely change this (for R-devel; possibly even consider "back" porting to R 4.1.1 patched). Thank you for the report and suggestion, Martin