Bug 14847 - get_all_vars returns mangled data frame
get_all_vars returns mangled data frame
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Models
R 2.14.1 patched
ix86 (32-bit) Linux
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-16 17:07 UTC by Patrick Breheny
Modified: 2012-04-17 21:19 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Breheny 2012-03-16 17:07:23 UTC
The code:

x <- 1:10
y <- rnorm(10)
fit <- lm(y~x)
get_all_vars(fit)

should return a data frame containing x and y, but it does not:

> get_all_vars(fit)
[1] y x
<0 rows> (or 0-length row.names)

The error is in the penultimate line of get_all_vars:

attr(x, "row.names") <- rownames

'x' is correct until this point; after this line it gets stuck with 0-length row names.  This can be fixed on the user end with, e.g.,:

> g <- get_all_vars(fit)
> attr(g,"row.names") <- 1:10
> g
            y  x
1  -1.3069121  1
2   0.1132448  2
3  -1.2168654  3
4  -0.1506071  4
5   1.1304623  5
6   0.5477071  6
7   2.1261278  7
8   0.2911167  8
9   0.6624049  9
10 -2.0740357 10

But it would be better to fix get_all_vars internally.
Comment 1 Duncan Murdoch 2012-04-17 21:19:07 UTC
Fixed, thanks.