Skip to content

get_all_vars fails with matrices (PR#13624)

3 messages · Simon Wood, Peter Dalgaard

#
Hi,

According to the help file for model.frame/get_all_vars, the following should 
produce the same output from both functions, but it doesn't...
z X.1 X.2 X.3
1 26   1   6  11
2 27   2   7  12
3 28   3   8  13
4 29   4   9  14
5 30   5  10  15
[1] z    X    <NA> <NA>
<0 rows> (or 0-length row.names)
-- the equivalent works ok if there are no matrices involved. 

I'm using  R version 2.9.0 alpha (2009-03-24 r48212) (Suse linux 10 and 11, 64 
bit intel). I found the problem while trying to fix a problem in an mgcv 
plotting routine.

best,
Simon
#
s.wood at bath.ac.uk wrote:
This works, though:

 > dat <- data.frame(X=I(matrix(1:15,5,3)),z=26:30)
 > get_all_vars(~z+X,dat)
    z X.1 X.2 X.3
1 26   1   6  11
2 27   2   7  12
3 28   3   8  13
4 29   4   9  14
5 30   5  10  15

but there is something special with lists:

 > dat <- as.data.frame(list(X=I(matrix(1:15,5,3)),z=26:30))
 > get_all_vars(~z+X,dat)
    z X.1 X.2 X.3
1 26   1   6  11
2 27   2   7  12
3 28   3   8  13
4 29   4   9  14
5 30   5  10  15
 > dat <- data.frame(list(X=I(matrix(1:15,5,3)),z=26:30))
 > get_all_vars(~z+X,dat)
    z X.1 X.2 X.3
1 26   1   6  11
2 27   2   7  12
3 28   3   8  13
4 29   4   9  14
5 30   5  10  15
 > dat <- list(X=I(matrix(1:15,5,3)),z=26:30)
 > get_all_vars(~z+X,dat)
[1] z X
<0 rows> (or 0-length row.names)
 >
#
It's not just lists that are odd...
z X.1 X.2 X.3
1 26   1   6  11
2 27   2   7  12
3 28   3   8  13
4 29   4   9  14
5 30   5  10  15
[1] z    X    <NA> <NA>

... which is again a problem when trying to pick up unprocessed versions of 
the variables used by a modelling function....
On Wednesday 25 March 2009 18:54, Peter Dalgaard wrote: