R-alpha: attach() bug

Peter Dalgaard BSA (p.dalgaard@kubism.ku.dk)
04 Mar 1997 12:42:14 +0100


To: R-testers@stat.math.ethz.ch
Subject: R-alpha: attach() bug
From: Peter Dalgaard BSA <p.dalgaard@kubism.ku.dk>
Date: 04 Mar 1997 12:42:14 +0100
Message-Id: <x2d8tfdgtl.fsf@bush.kubism.ku.dk>


R has:

> attach(data)
> attach(data[-1])
> search()
[1] ".GlobalEnv" "data"       "data[-1]"   ".SystemEnv"

This is opposite of Splus:

> attach(data)
> attach(data[-1])
> search()
 [1] "/home/sfe/pd/.Data"                            
 [2] "data[-1]"                                      
 [3] "data"                                          
 [4] "/opt/local/lib/splus-3.4/splus/.Functions"     
 [5] "/opt/local/lib/splus-3.4/stat/.Functions"      
 [6] "/opt/local/lib/splus-3.4/s/.Functions"         
 [7] "/opt/local/lib/splus-3.4/s/.Datasets"          
 [8] "/opt/local/lib/splus-3.4/stat/.Datasets"       
 [9] "/opt/local/lib/splus-3.4/splus/.Datasets"      
[10] "/opt/local/lib/splus-3.4/library/trellis/.Data"

Of course, I could just detach() in between, but not having the last
attachment searched first gives some nasty bug opportunities. It's
confusing enough that .GlobalEnv (or the .Data directory) gets
searched before dataframes[*], but at least we have bug compatibility
there.

[*] For instance, you easily find yourself doing this, but it doesn't work:

attach(data); dif<- x - y; data$dif<-dif; detach()
attach(data[data$age < 25,]); plot(age, dif)
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-