Skip to content

rbind fails with zero row data.frame and non-data.frame (PR#9657)

2 messages · Michael Lawrence, Brian Ripley

#
Full_Name: Michael Lawrence
Version: 2.5.0
OS: Linux
Submission from: (NULL) (69.5.145.41)


With R 2.5.0, when trying to rbind a zero row data.frame to a 
non-data.frame (eg character vector), the following error is output:
Error in all.levs[[j]] : subscript out of bounds

Here is the code to reproduce the error:
rbind(data.frame(foo=character(0), bar=character(0)), c(foo="foo", bar="bar"))

It seems that the code assumes that it has at least one data.frame but 
the data.frame was filtered out at the beginning, because it had zero 
rows.

--please do not edit the information below--
Version:
 platform = i686-pc-linux-gnu
 arch = i686
 os = linux-gnu
 system = i686, linux-gnu
 status = 
 major = 2
 minor = 5.0
 year = 2007
 month = 04
 day = 23
 svn rev = 41293
 language = R
 version.string = R version 2.5.0 (2007-04-23)

Locale:
C

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils,
package:datasets, package:methods, Autoloads, package:base
#
Thank you, fixed in 2.5.0 patched:
X.a. X.b.
1    a    b

Note though that rbind-ing a character vector to a data frame does not in 
general work well:
foo  bar
1
2
3 <NA> <NA>
Warning messages:
1: invalid factor level, NAs generated in: `[<-.factor`(`*tmp*`, ri, value 
= "a")
2: invalid factor level, NAs generated in: `[<-.factor`(`*tmp*`, ri, value 
= "b")

and I am not sure that one should expect it to do so.
On Sat, 5 May 2007, lawremi at iastate.edu wrote: