[Rd] Bug in copying of S4 objects (PR#8112)

murdoch@stats.uwo.ca murdoch at stats.uwo.ca
Wed Aug 31 20:48:20 CEST 2005

If I have an S4 object, and I make a copy, changes to the original 
aren't reflected in the copy:

 > setClass("foo", representation(slot="numeric"))
 > x <- new("foo", slot=1)
 > y <- x
 > x at slot <- 2
 > y
An object of class "foo"
Slot "slot":
[1] 1

This is as it should be.  However, if I call the slot assignment 
function in a funny way, y *does* receive the changes:

 > x <- new("foo", slot=1)
 > y <- x
 > assign("x", "@<-"(x, "slot", 2))
 > y
An object of class "foo"
Slot "slot":
[1] 2

This happens in the current R-devel in Windows, and R-patched too.

 > version
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status   Under development (unstable)
major    2
minor    2.0
year     2005
month    08
day      31
svn rev  35467
language R

Duncan Murdoch

More information about the R-devel mailing list