[Rd] `as.data.frame.matrix()` can produce a data frame without a `names` attribute

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri Mar 22 11:54:34 CET 2024


>>>>> Martin Maechler 
>>>>>     on Fri, 22 Mar 2024 11:17:34 +0100 writes:

>>>>> Davis Vaughan via R-devel 
>>>>>     on Thu, 21 Mar 2024 15:10:29 -0400 writes:

    >> Hi all,

    >> I recently learned that it is possible for
    >> `as.data.frame.matrix()` to produce a data frame with 0
    >> columns that is also entirely missing a `names`
    >> attribute, and I think this is a bug:

    >> ``` # No `names`, weird!
    >> attributes(as.data.frame(matrix(nrow = 0, ncol = 0))) #>
    >> $class #> [1] "data.frame"
    >> #>
    >> #> $row.names #> integer(0)

    >> # This is what I expected attributes(data.frame()) #>
    >> $names #> character(0)
    >> #>
    >> #> $row.names #> integer(0)
    >> #>
    >> #> $class #> [1] "data.frame" ```

    >> In my experience, 0 column data frames should probably
    >> still have a `names` attribute, and it should be set to
    >> `character()`.

    > I agree.

    > A (very nice IMO) patch I'm currently testing is

>     317c317
>     < 	names(value) <- collabs
>     ---
>     > 	names(value) <- collabs %||% character()


Commited to R's (R-devel) sources in svn rev 86169   .. to
become R 4.4.0 soonish.

Martin



More information about the R-devel mailing list