From timhesterberg at gmail.com  Wed Aug 27 19:05:19 2008
From: timhesterberg at gmail.com (timhesterberg at gmail.com)
Date: Wed, 27 Aug 2008 19:05:19 +0200 (CEST)
Subject: [Rd] format.data.frame handles names in nested data frames badly
	(PR#12624)
Message-ID: <20080827170519.78A0B282C761@mail.pubhealth.ku.dk>

> d <- data.frame(x=1:3, y=2:4)
> d[["r"]] <- d[1]/d[2]
> d
  x y         x
1 1 2 0.5000000
2 2 3 0.6666667
3 3 4 0.7500000

It appears that the name "x" was given
instead of "r".  That is not correct:

> names(d)
[1] "x" "y" "r"
> showStructure(d) # from package splus2R
list[3,3]  S3 class: data.frame
 &row.names   numeric[ length 3]  class: integer
 $x   numeric[ length 3]  class: integer
 $y   numeric[ length 3]  class: integer
 $r   list[3,1]  S3 class: data.frame
   &row.names     numeric[ length 3]  class: integer
   $x     numeric[ length 3]  class: numeric

print.data.frame calls format.data.frame, which
loses the name "r" and substitutes the name "x".

I suggest that format.data.frame (or print.data.frame)
paste together the names, e.g.
  x y       r.x
1 1 2 0.5000000
2 2 3 0.6666667
3 3 4 0.7500000
This generalizes to the case that an included data frame
includes two columns.  It is also consistent with the
behavior for a data frame containing a matrix.

> d <- data.frame(x=1:3, y=2:4, A = I(cbind(a=3:5,b=4:6)))
> d
  x y A.a A.b
1 1 2   3   4
2 2 3   4   5
3 3 4   5   6
> showStructure(d)
list[3,3]  S3 class: data.frame
 &row.names   numeric[ length 3]  class: integer
 $x   numeric[ length 3]  class: integer
 $y   numeric[ length 3]  class: integer
 $A   numeric[3,2]  S3 class: AsIs
   attributes: dimnames

--please do not edit the information below--

Version:
 platform = i486-pc-linux-gnu
 arch = i486
 os = linux-gnu
 system = i486, linux-gnu
 status =
 major = 2
 minor = 7.1
 year = 2008
 month = 06
 day = 23
 svn rev = 45970
 language = R
 version.string = R version 2.7.1 (2008-06-23)

Locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

Search Path:
 .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate,
package:stats, package:graphics, package:grDevices, package:utils,
package:datasets, package:showStructure, package:splus2R, package:methods,
Autoloads, package:base

	[[alternative HTML version deleted]]



[Rd] format.data.frame handles names in nested data frames badly (PR#12624)
timhesterberg at gmail.com