ripley@stats.ox.ac.uk
2003-Jan-30 23:56 UTC
[Rd] empty array indexing with dimnames (PR#2507)
On Thu, 30 Jan 2003 maechler@stat.math.ethz.ch wrote:> This is a bug that will not often trigger, and only happens for arrays > (but not matrices) ending up with 0 dimensions:The bug is a missing else branch of an if condition at line 431 of subset.c. I don't think the buglets are wrong. You don't drop length 0 dimensions. If you did, the object would be of the wrong length. You only drop length 1 dimensions.> > The following code also shows two 'buglets' (the first even for > matrix indexing) where "drop = TRUE/FALSE" is not correctly obeyed. > One can argue that since all these arrays have length zero, it > shouldn't matter what dimensions they get. > [But this shouldn't distract from the real bug giving errors > where it shouldn't!] > > > ##-- this kind of indexing works with matrices (with dimnames): > m <- cbind(x = 1, y = 1:3) > str(m[1, 0])# drops dimension > str(m[1:2,0])# doesn't drop <<< ? buglet > str(m[1, 0, drop=FALSE]) > str(m[1:2,0, drop=FALSE]) > > > ## these apply (not too relevant here) > stopifnot(identical(m[1, 0], > m[1, integer(0)])) > stopifnot(identical(m[1, 0, drop=FALSE], > m[1, integer(0), drop=FALSE])) > > ###--- but it fails with arrays --- > > dn <- list(LETTERS[1:2], letters[1:3], paste("t",1:4,sep="")) > A. <- array(1:24, dim = 2:4) # no dimnames > Ad <- A.; dimnames(Ad) <- dn # with dimnames > > ## works `ok', if no dimnames --- not always obeying "drop=" --> 2nd buglet! > for(O in list(0, integer(0))) { > str(A.[1, O, 2 ]) # int(0) > str(A.[O,-1, O ])# int[0, 1:2, 0] > str(A.[O, O,2:3])# int[0, 0, 1:2] > > ## with drop = FALSE: > str(A.[1, O, 2 , drop=FALSE])# int[1, 0, 1] > str(A.[O,-1, O , drop=FALSE])# int[0, 1:2, 0] > str(A.[O, O,2:3, drop=FALSE])# int[0, 0, 1:2] > cat("---\n") > } > > ##-- identical with `Ad' instead of `A.', i.e., *with* dimnames: > ##--> All 6 statements fail : > > O <- 0##__for(O in list(0, integer(0))) { > > try(Ad[1, O, 2 ]) # int(0) > try(Ad[O,-1, O ])# int[0, 1:2, 0] > try(Ad[O, O,2:3])# int[0, 0, 1:2] > > ## with drop = FALSE: > try(Ad[1, O, 2 , drop=FALSE])# int[1, 0, 1] > try(Ad[O,-1, O , drop=FALSE])# int[0, 1:2, 0] > try(Ad[O, O,2:3, drop=FALSE])# int[0, 0, 1:2] > cat("---\n") > ##__} > > ______________________________________________ > R-devel@stat.math.ethz.ch mailing list > http://www.stat.math.ethz.ch/mailman/listinfo/r-devel >-- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
maechler@stat.math.ethz.ch
2003-Jan-31 09:24 UTC
[Rd] empty array indexing with dimnames (PR#2507)
>>>>> "BDR" == Brian D Ripley <ripley@stats.ox.ac.uk> >>>>> on Thu, 30 Jan 2003 23:49:22 +0100 (MET) writes:BDR> On Thu, 30 Jan 2003 maechler@stat.math.ethz.ch wrote: >> This is a bug that will not often trigger, and only >> happens for arrays (but not matrices) ending up with 0 >> dimensions: BDR> The bug is a missing else branch of an if condition at BDR> line 431 of subset.c. and you have already fixed it for 1.7.0 BDR> I don't think the buglets are wrong. You don't drop BDR> length 0 dimensions. If you did, the object would be BDR> of the wrong length. You only drop length 1 dimensions. Yes, of course, you are right! <....> BDR> -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of BDR> Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ BDR> University of Oxford, Tel: +44 1865 272861 (self) 1 BDR> South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, BDR> UK Fax: +44 1865 272595 Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <><