From mark.bravington at csiro.au  Tue Jan  3 03:07:26 2006
From: mark.bravington at csiro.au (mark.bravington@csiro.au)
Date: Tue,  3 Jan 2006 03:07:26 +0100 (CET)
Subject: [Rd] load, environment[[, and attr<-/attributes<- (PR#8457)
Message-ID: <20060103020726.88AE0CD1B@slim.kubism.ku.dk>

Full_Name: Mark Bravington
Version: 2.2.1
OS: Windows XP
Submission from: (NULL) (203.132.243.69)


#       r-bugs at r-project.org

There is a bug to do with 'load', environment access via '[[', and 'attr<-' or
'attributes<-'. Modifying the attributes of a *copy* of an object can modify the
original too, under certain conditions:

 - the copy needs to be created using env[[ not by env$ nor just by name
 - the original object must have been 'load'ed and not subsequently
read-accessed before the copy was created
 
The script below might clarify this. BTW the problem is not only for
.GlobalEnv.

It's intriguing that 'load' doesn't seem to be "fully creating" the object-- is
it just creating a promise or something like that?

Mark Bravington
mark.bravington at csiro.au

a <- 1
attr( a, 'thing') <- 99
  
tf <- tempfile()
save( a, file=tf)

load( tf)
y <- .GlobalEnv[[ 'a']]
attr( y, 'thing') <- NULL
a # attr gone!

load( tf)
y <- .GlobalEnv$a
attr( y, 'thing') <- NULL
a # OK

load( tf)
a # to force access
y <- .GlobalEnv[[ 'a']]
attr( y, 'thing') <- NULL
a # OK

unlink( tf)



--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = 
 major = 2
 minor = 2.1
 year = 2005
 month = 12
 day = 20
 svn rev = 36812
 language = R

Windows XP Professional (build 2600) Service Pack 1.0

Locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252

Search Path:
 .GlobalEnv, package:methods, package:stats, package:graphics,
package:grDevices, package:utils, package:datasets, Autoloads, package:base



[Rd] load, environment[[, and attr<-/attributes<- (PR#8457)
mark.bravington@csiro.au