Alojz Loui Polic
2001-Mar-23 18:20 UTC
[R] newbie questions: attached data.frames and rm()
Hi I'm just starting with R-plus and I have noticed the following behaviour. If a data.frame is attached and then removed before being detached, the data is still present in the path and can accessed. Is this expected behaviour, and if so why? Thank you Loui below is sample code to show this, I'm using R-1.2.2 on Win-NT4 AA <- c(1, 1, 1, 1, 1) BB <- c(2, 3, 2, 1, 2) data1 <- data.frame( AA.data=AA, BB.data=BB ) ls() attach(data1) ls(2) rm(data1) ls() ls(2) AA.data[1] -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Mar-23 22:17 UTC
[R] newbie questions: attached data.frames and rm()
Alojz Loui Polic <lpolic at ineural.com> writes:> Hi > > I'm just starting with R-plus and I have noticed?????> the following behaviour. > > If a data.frame is attached and then removed before > being detached, the data is still present in the > path and can accessed. Is this expected behaviour, > and if so why?It's designed that way. Whether or not that is a good thing is debatable - people easily get bitten from attaching a data frame and modifying it without that affecting the attached version. One upside is that the argument to attach() can be an arbitrary expression, e.g. AA <- c(1, 1, 1, 1, 1) BB <- c(2, 3, 2, 1, 2) attach(data.frame( AA.data=AA, BB.data=BB) [It is not a trivial exercise to think up an alternative semantic model for attached objects. One problem being that modifying an object in R is more often than not a compute-and-rename operation, so accessing an object by reference is not possible (although reference by name is).] -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._