murdoch at stats.uwo.ca
2006-Sep-30 13:09 UTC
[Rd] Strange behaviour of the [[ operator (PR#9263)
On 9/29/2006 9:06 PM, Herve Pages wrote:> Hi, > > This looks like a bug: > > > a <- list(b=5) > > a[['b']] > [1] 5 > > a[[t<-'b']] > > Nothing gets printed! > > I need to use parenthesis to see the expected result: > > > a[[(t<-'b')]] > [1] 5Yes, I agree it looks like a bug, and it's still there in R-devel. The problem is that the assignment sets the R_Visible flag to false, and the indexing never sets it to true. The same problem happens with a[t <- 'b'], whether a is a list or not: > a <- c(b=5, c=6, d=7) > a[t <- 'b'] > .Last.value b 5 Duncan Murdoch
hpages at fhcrc.org
2006-Sep-30 16:37 UTC
[Rd] Strange behaviour of the [[ operator (PR#9263)
Hi Duncan, This is even more confusing with a matrix: > x <- matrix(5:-6, 3) > x [,1] [,2] [,3] [,4] [1,] 5 2 -1 -4 [2,] 4 1 -2 -5 [3,] 3 0 -3 -6 > x[invisible(2),3] [1] -2 > x[2,invisible(3)] > .Last.value [1] -2 Thanks, H. Quoting murdoch at stats.uwo.ca:> On 9/29/2006 9:06 PM, Herve Pages wrote: > > Hi, > > > > This looks like a bug: > > > > > a <- list(b=5) > > > a[['b']] > > [1] 5 > > > a[[t<-'b']] > > > > Nothing gets printed! > > > > I need to use parenthesis to see the expected result: > > > > > a[[(t<-'b')]] > > [1] 5 > > Yes, I agree it looks like a bug, and it's still there in R-devel. The > problem is that the assignment sets the R_Visible flag to false, and the > indexing never sets it to true. The same problem happens with a[t <- > 'b'], whether a is a list or not: > > > a <- c(b=5, c=6, d=7) > > a[t <- 'b'] > > .Last.value > b > 5 > > Duncan Murdoch > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >