Duncan Murdoch <murdoch.dun...@gmail.com> writes: > On 09/05/2014, 6:54 AM, Rainer M Krug wrote: >> >> How can I access an object in an attached but deleted environment, when >> the object also exists in the .GolbalEnv? > > Attaching a variable to the search list generally makes a copy of it, > so it can't be "attached but deleted". However, "making a copy" of an > environment just copies the reference to it, so your environment still > exists on the search list, it just doesn't have a name in the global > environment.
I was aware that my wording was not the best - your explanation makes the whole process much clearer - thanks. > >> >> I hope the example below makes the question clear: >> >> --8<---------------cut here---------------start------------->8--- >> tmp <- attach(what=NULL, name="org:variables") >> tmp$test = 13 >> rm(tmp) >> test >> # > 13 >> test <- 24 >> test >> # > 24 >> ls(all=TRUE) >> # > character(0) > > I don't know why you would have seen character(0) here. You should > have seen "test" in the list, because you created it a couple of lines > earlier. You are right. Wrong copy - paste. My fault. > >> # >> # how can I access the variable test in the object org:variables in the >> # search path? >> # >> rm(test) >> test >> # > 13 >> --8<---------------cut here---------------end--------------->8--- >> >> Any suggestions? > > You can use assign, or get a reference to the environment using > as.environment("org:variables"), and access it within that. For > example, > > assign("test", 24, pos="org:variables") > > or > > e <- as.environment("org:variables") > e$test <- 24 Perfect - that is what I was looking for. Both will work perfectly in my case. Thanks lot, Rainer > > Duncan Murdoch -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Stellenbosch University South Africa Tel : +33 - (0)9 53 10 27 44 Cell: +33 - (0)6 85 62 59 98 Fax : +33 - (0)9 58 10 27 44 Fax (D): +49 - (0)3 21 21 25 22 44 email: rai...@krugs.de Skype: RMkrug PGP: 0x0F52F982
pgpwlcZ10K4Mk.pgp
Description: PGP signature
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel