From luke-tierney at uiowa.edu  Thu Jan 17 20:26:58 2013
From: luke-tierney at uiowa.edu (luke-tierney at uiowa.edu)
Date: Thu, 17 Jan 2013 13:26:58 -0600
Subject: [Rd] Bug in list subset assignment due to NAMED optimization
In-Reply-To: <CALLn38PewFgLO-SnLv+8Pk5UDpDKwJFX4rtrV9w5VOC8Os4u-A@mail.gmail.com>
References: <CALLn38PewFgLO-SnLv+8Pk5UDpDKwJFX4rtrV9w5VOC8Os4u-A@mail.gmail.com>
Message-ID: <alpine.LFD.2.03.1301171325530.1915@uiowa.edu>

Thanks for the report.  This is now fixed in R-devel and R-patched
by increasing NAMED on the RHS value to 2 when it is not 0.

Best,

luke

On Tue, 8 Jan 2013, Justin Talbot wrote:

> In R version 2.15.2 (2012-10-26) i386-apple-darwin9.8.0/i386 (32-bit) I get
> the following:
>
>> a <- list(1)
>> (a[[1]] <- a)
> [[1]]
> [[1]][[1]]
> [1] 1
>
> but
>
>> a <- list(1)
>> b <- a
>> (a[[1]] <- a)
> [[1]]
> [1] 1
>
> And similarly:
>
>> a <- list(x=1)
>> (a$x <- a)
> $x
> $x$x
> [1] 1
>
> but
>
>> a <- list(x=1)
>> b <- a
>> (a$x <- a)
> $x
> [1] 1
>
> In both cases the result of the first sequence is wrong. It's returning the
> updated `a` rather than the RHS of the assignment. The second sequence in
> both cases is correct; the assignment to `b` increments the NAMED value
> causing the necessary copy to be made so the RHS is returned from the
> assignment.
>
> Would it be sufficient to add a check to do_subassign2_dflt
> and do_subassign3_dflt that creates a duplicate of the LHS if the LHS & RHS
> are the same object?
>
> Justin
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] Bug in list subset assignment due to NAMED optimization
luke-tierney at uiowa.edu