[Rd] rbind.data.frame converts character column to factor (PR#9917)

sebastien.villemot at ens.fr sebastien.villemot at ens.fr
Tue Sep 18 18:37:44 CEST 2007


Full_Name: Sébastien Villemot
Version: 2.5.1
OS: Debian GNU/Linux (Testing aka "Lenny")
Submission from: (NULL) (193.51.127.120)


Here is the transcript of a R session under version 2.5.1:

> x <- data.frame(a = I(character(0)))
> typeof(x$a)
[1] "character"
> x <- rbind(x, list(a = "foo"))
> typeof(x$a)
[1] "integer"

The column "a" has been converted from character to factor.

This was not happening under version 2.4.0 Patched (2006-11-25 r39997):
> x <- data.frame(a = I(character(0)))
> typeof(x$a)
[1] "character"
> x <- rbind(x, list(a = "foo"))
> typeof(x$a)
[1] "character"

Furthermore, the bug doesn't show up (in 2.5.1) if the data frame is initially
non-empty:
> x <- data.frame(a = I("bar"))
> typeof(x$a)
[1] "character"
> x <- rbind(x, list(a = "foo"))
> typeof(x$a)
[1] "character"

Best,

Sébastien Villemot



More information about the R-devel mailing list