lawremi at iastate.edu
2007-May-05 12:01 UTC
[Rd] rbind fails with zero row data.frame and non-data.frame (PR#9657)
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
Prof Brian Ripley
2007-May-06 07:04 UTC
[Rd] (PR#9657) rbind fails with zero row data.frame and non-data.frame
Thank you, fixed in 2.5.0 patched:> A <- data.frame(foo=character(0), bar=character(0)) > rbind(A, c(foo="a", bar="b"))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:> A <- data.frame(foo=character(2), bar=character(2)) > rbind(A, c(foo="a", bar="b"))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:> 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595