Bug 16442 - rbind() produces wrong row numbers when the first argument is an empty dataframe
Summary: rbind() produces wrong row numbers when the first argument is an empty dataframe
Alias: None
Product: R
Classification: Unclassified
Component: Add-ons (show other bugs)
Version: R 3.1.3
Hardware: ix86 (32-bit) Windows 64-bit
: P5 normal
Assignee: R-core
Depends on:
Reported: 2015-06-23 11:03 UTC by soushong
Modified: 2018-02-19 07:42 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description soushong 2015-06-23 11:03:49 UTC
It seems there is a bug in rbind() related to row numbering. To reproduce the bug, please run the code below. 

Whenever an empty dataframe is used as the first argument in rbind(), the variable cfg.df gets assigned row number "2" for the first added row, instead of "1".
Afterwards, rbind() assigns row number "21" instead of "2" for the second row.

If you keep adding rows till you get 21 rows, 
rbind() will create row number 211 instead of "21".

Even if this behavior is intended to preserve the uniqueness of row names, there is a definite inconsistency with trying to use row number "2" twice in the beginning (with the second attempt resulting in "21", possibly to maintain the uniqueness of the row).

Unsystematic row numbering will be a cause of wasted time, because one automatically perceives this 'feature' as a bug in one's code or in R.

# run the code below to demonstrate the bug

addCfgLine <- function(conf.df, param=NULL, paramvalue=NULL)
    # check that param & paramvalue are both != NULL

    savedNames <- names(conf.df)
    ttmp.df <- rbind( conf.df
                     ,setNames( as.list(c(param,paramvalue))
    return( ttmp.df )

cfg.df <- data.frame( param=character()

cfg.df <- addCfgLine(cfg.df, "option1_name",              "DEFAULT_01")
cfg.df <- addCfgLine(cfg.df, "option2_name",              "DEFAULT_02")

Comment 1 Benjamin Tyner 2018-02-09 20:49:23 UTC
This can be closed; was fixed with R version 3.3.0; perhaps related to https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16570 or https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=16666