Skip to content
Prev 169897 / 398506 Next

Problem with retrieving updated variables after attach()

attach provides a copy of rather than aliases to the variables within a
data frame.

d = data.frame(x=0)
attach(d)

x
# 0, from the attached copy of d

x = 1
x
# 1, from the global anvironment
d$x
# 0, from d

x <<- 2
x
# 1, from the global environment
d$x
# 0, from d
get('x', pos=2)
# 2, from the attached copy of d

rm(x)
x
# 2, from the attached copy of d

vQ
David Croll wrote: