Skip to content

bug in rbind.data.frame: wrong rownames (PR#8506)

1 message · Deepayan Sarkar

#
Hi,

there is a bug in the calculation of row names in rbind.data.frame.
When one of the arguments has 0 rows but is named in the call, this
mistakenly contributes an element in the "row.names" attribute of the
result, e.g.:
[1] 5 2
[1] 6 2
Version 2.3.0 Under development (unstable) (2006-01-17 r37109)
i686-pc-linux-gnu

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "base"

This happens because
[1] "1" "2" "3" "4" "5"
[1] "a.1" "a.2" "a.3" "a.4" "a.5" "b"

I think the following patch (to the 'Make.row.names' function defined
inside rbind.data.frame) fixes this:

-Deepayan

Index: src/library/base/R/dataframe.R
===================================================================
--- src/library/base/R/dataframe.R      (revision 37109)
+++ src/library/base/R/dataframe.R      (working copy)
@@ -886,7 +886,7 @@
        if(nchar(nmi) > 0) {
            if(ni > 1)
                paste(nmi, ri, sep = ".")
-           else nmi
+           else nmi[ri]
        }
        else if(nrow > 0 && identical(ri, 1:ni))
            seq(from = nrow + 1, length = ni)