[Rd] inconsistency within within( ) (PR#11131)

jritter at umn.edu jritter at umn.edu
Thu Apr 10 20:20:32 CEST 2008


Hello R-team ~

I ran across an inconsistency about how within( ) handles expressions 
like b<-NULL.  (I have found within( ) very handy, by the way.)  The 
problem appears to crop up when you use something like b<-NULL in the 
same within() call that creates a new variable in the data frame.  An 
example using 2.6.2 on Windows XP is below.  Version 2.6.1 had a 
different, but similar problem.

As always, thanks for a very useful piece of software.

Joe Ritter

 > a<-1:5;b<-2:6;c<-3:7
 > abc=data.frame(a,b,c)
 > within(abc,{b<-NULL})
   a c
1 1 3
2 2 4
3 3 5
4 4 6
5 5 7
 > within(abc,{d<-a+7;b<-NULL})
   a c    d structure(c(" 8", " 9", "10", "11", "12"), class = "AsIs")
1 1 3 NULL                                                          8
2 2 4 <NA>                                                          9
3 3 5 <NA>                                                         10
4 4 6 <NA>                                                         11
5 5 7 <NA>                                                         12
Warning message:
In format.data.frame(x, digits = digits, na.encode = FALSE) :
   corrupt data frame: columns will be truncated or padded with NAs
 > within(abc,{a<-a+7;b<-NULL})
    a c
1  8 3
2  9 4
3 10 5
4 11 6
5 12 7



More information about the R-devel mailing list