Several bugs are present in R-2.15.3 and R-alpha due to naive copying of list elements. The bug below is due to naive copying in subset.c (with similar bugs for matrices and arrays): a<-list(c(1,2),c(3,4),c(5,6)) b<-a[2:3] a[[2]][2]<-9 print(b[[1]][2]) Naive copying in mapply.c leads to the following bug: X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A) X[1]<-99 print(A) Similar bugs exist in eapply, rapply, and vapply.
Bugs due to naive copying of list elements
5 messages · Radford Neal, David Winsemius, Steven McKinney +2 more
On Mar 12, 2013, at 3:59 AM, Radford Neal wrote:
Several bugs are present in R-2.15.3 and R-alpha due to naive copying of list elements. The bug below is due to naive copying in subset.c (with similar bugs for matrices and arrays): a<-list(c(1,2),c(3,4),c(5,6)) b<-a[2:3] a[[2]][2]<-9 print(b[[1]][2])
This is an example of lazy evaluation, right?
Naive copying in mapply.c leads to the following bug: X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A) X[1]<-99 print(A)
Is this a bug in mapply()? or in print()? I thought 'print' should evaluate its argument and "force" the promise to be executed. Or does it just return the same promise as was passed to it? Compare: X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A); str(A) X[1]<-99 print(A) Could someone could comment on what 'force' actually does. I am unclear why force(A) in the code above in the pace of str(A) did not have the effect I expected, whereas str(b) or str(A) did have that effect.
a<-list(c(1,2),c(3,4),c(5,6)) b<-a[2:3]; force(b)
[[1]] [1] 3 4 [[2]] [1] 5 6
a[[2]][2]<-9 print(b[[1]][2])
[1] 9 #----------
X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A); force(A)
[[1]] [1] 2 [[2]] [1] 2 [[3]] [1] 2 [[1]] [1] 2 [[2]] [1] 2 [[3]] [1] 2
X[1]<-99 print(A)
[[1]] [1] 99 [[2]] [1] 99 [[3]] [1] 99
Similar bugs exist in eapply, rapply, and vapply.
David Winsemius Alameda, CA, USA
Whereas
a <- list(c(1,2),c(3,4),c(5,6)) b <<- a[2:3] a[[2]][2] <- 9 b
[[1]] [1] 3 4 [[2]] [1] 5 6
Examples such as this leave me in a cold sweat - where did I miss the documentation describing Radford's case? Can anyone point to the documentation that describes Radford's outcome? (It looks very lisp-like. Is it linked to R's origins in lisp?) I get the same outcome in R-2.11.1 so it is nothing new. I can only hope I have not set up such an effect in analysis scripts I've used to generate reproducible publication output. Steven McKinney
From: r-devel-bounces at r-project.org [r-devel-bounces at r-project.org] On Behalf Of David Winsemius [dwinsemius at comcast.net]
Sent: March 12, 2013 10:28 AM
To: Radford Neal
Cc: r-devel at r-project.org
Subject: Re: [Rd] Bugs due to naive copying of list elements
Sent: March 12, 2013 10:28 AM
To: Radford Neal
Cc: r-devel at r-project.org
Subject: Re: [Rd] Bugs due to naive copying of list elements
On Mar 12, 2013, at 3:59 AM, Radford Neal wrote: > Several bugs are present in R-2.15.3 and R-alpha due to > naive copying of list elements. > > The bug below is due to naive copying in subset.c (with > similar bugs for matrices and arrays): > > a<-list(c(1,2),c(3,4),c(5,6)) > b<-a[2:3] > a[[2]][2]<-9 > print(b[[1]][2]) This is an example of lazy evaluation, right? > > Naive copying in mapply.c leads to the following bug: > > X<-1+1 > f<-function(a,b) X > A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) > print(A) > X[1]<-99 > print(A) > Is this a bug in mapply()? or in print()? I thought 'print' should evaluate its argument and "force" the promise to be executed. Or does it just return the same promise as was passed to it? Compare: X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A); str(A) X[1]<-99 print(A) Could someone could comment on what 'force' actually does. I am unclear why force(A) in the code above in the pace of str(A) did not have the effect I expected, whereas str(b) or str(A) did have that effect. > a<-list(c(1,2),c(3,4),c(5,6)) > b<-a[2:3]; force(b) [[1]] [1] 3 4 [[2]] [1] 5 6 > a[[2]][2]<-9 > print(b[[1]][2]) [1] 9 #---------- > X<-1+1 > f<-function(a,b) X > A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) > print(A); force(A) [[1]] [1] 2 [[2]] [1] 2 [[3]] [1] 2 [[1]] [1] 2 [[2]] [1] 2 [[3]] [1] 2 > X[1]<-99 > print(A) [[1]] [1] 99 [[2]] [1] 99 [[3]] [1] 99 > Similar bugs exist in eapply, rapply, and vapply. > -- David Winsemius Alameda, CA, USA ______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20130312/318362b3/attachment.pl>
Thanks for the report. Fixed in r62220 on trunk, r62221 on R-3-0-branch, and r62222 on R-2-15-branch. Best, luke
On Tue, 12 Mar 2013, Radford Neal wrote:
Several bugs are present in R-2.15.3 and R-alpha due to naive copying of list elements. The bug below is due to naive copying in subset.c (with similar bugs for matrices and arrays): a<-list(c(1,2),c(3,4),c(5,6)) b<-a[2:3] a[[2]][2]<-9 print(b[[1]][2]) Naive copying in mapply.c leads to the following bug: X<-1+1 f<-function(a,b) X A<-mapply(f,c(1,2,3),c(4,5,6),SIMPLIFY=FALSE) print(A) X[1]<-99 print(A) Similar bugs exist in eapply, rapply, and vapply.
______________________________________________ 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