[Rd] Bug in list subset assignment due to NAMED optimization
luke-tierney at uiowa.edu
luke-tierney at uiowa.edu
Wed Jan 9 16:16:56 CET 2013
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?
Thanks -- that's probably the best fix but I want to think it thorugh
a bit more before committing.
Best,
luke
>
> 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
More information about the R-devel
mailing list