[Rd] as.data.frame and illegal row.names argument (bug in package:DoE.wrapper?)

William Dunlap wdunlap at tibco.com
Wed Jan 13 22:46:05 CET 2016


as.data.frame methods behave inconsistently when they are given a row.name
argument of the wrong length.  The matrix method silently ignores row.names
if it has the wrong length and the numeric, integer, and character methods
do not bother to check and thus make an illegal data.frame.

> as.data.frame(matrix(1:6,nrow=3), row.names=c("One","Two"))
  V1 V2
1  1  4
2  2  5
3  3  6
> as.data.frame(1:3, row.names=c("One","Two"))
    1:3
One   1
Two   2
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs
> as.data.frame(c("a","b","c"), row.names=c("One","Two"))
    c("a", "b", "c")
One                a
Two                b
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
  corrupt data frame: columns will be truncated or padded with NAs

(The warnings are from the printing, not the making, of the data.frames.)

I ran into this while using the DoE.wrapper package, which has what I think
is a typo,
giving "t" as the row.names for the output of mapply():
   cross.design.R:    ro <- as.data.frame(mapply("touter",ro1, ro2,
"paste", sep="_"),"t")

I don't know all the reasons why people use as.data.frame instead of
data.frame.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

	[[alternative HTML version deleted]]



More information about the R-devel mailing list