Bug 13624 - get_all_vars fails with matrices
Summary: get_all_vars fails with matrices
Status: ASSIGNED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: old
Hardware: All All
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2009-03-25 21:54 UTC by Jitterbug compatibility account
Modified: 2010-04-12 06:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2009-03-25 21:54:55 UTC
From: Simon Wood <s.wood@bath.ac.uk>
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...

> dat <- list(X=matrix(1:15,5,3),z=26:30)
> model.frame(~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
> get_all_vars(~z+X,dat)
[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
-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283

Comment 1 Jitterbug compatibility account 2009-03-25 23:54:38 UTC
From: Peter Dalgaard <p.dalgaard@biostat.ku.dk>
s.wood@bath.ac.uk wrote:
> 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...
> 
>> dat <- list(X=matrix(1:15,5,3),z=26:30)
>> model.frame(~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
>> get_all_vars(~z+X,dat)
> [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

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)
 >


-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)              FAX: (+45) 35327907

Comment 2 Jitterbug compatibility account 2009-03-26 20:17:33 UTC
From: Simon Wood <s.wood@bath.ac.uk>
It's not just lists that are odd...

> X <- matrix(1:15,5,3)
> z <- 26:30
> model.frame(~z+X)
   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
> get_all_vars(~z+X)
[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:
> s.wood@bath.ac.uk wrote:
> > 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...
> >
> >> dat <- list(X=matrix(1:15,5,3),z=26:30)
> >> model.frame(~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
> >
> >> get_all_vars(~z+X,dat)
> >
> > [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
>
> 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)

-- 
> Simon Wood, Mathematical Sciences, University of Bath, Bath, BA2 7AY UK
> +44 1225 386603  www.maths.bath.ac.uk/~sw283