From luke at stat.uiowa.edu  Fri Sep  2 03:36:16 2005
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Thu, 1 Sep 2005 20:36:16 -0500 (CDT)
Subject: [Rd] Bug in copying of S4 objects (PR#8112)
In-Reply-To: <20050831184820.9612B1992B@slim.kubism.ku.dk>
References: <20050831184820.9612B1992B@slim.kubism.ku.dk>
Message-ID: <Pine.LNX.4.63.0509012034570.15992@itasca2.wildberry.org>

Another variant of what is probably the same issue:

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

     > y
     An object of class ???foo???
     Slot "a":
     [1] 2

luke

On Wed, 31 Aug 2005, murdoch at stats.uwo.ca wrote:

> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


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