From thomas@biostat.washington.edu  Wed Aug 20 18:21:25 1997
From: thomas@biostat.washington.edu (Thomas Lumley)
Date: Wed, 20 Aug 1997 10:21:25 -0700 (PDT)
Subject: R-alpha: R-0.50-a3: [logical, drop = FALSE] -- bug in R (and S-plus)
In-Reply-To: <199708201706.TAA02765@sophie.ethz.ch>
Message-ID: <Pine.SUN.3.95.970820101359.641C-100000@chekov>

On Wed, 20 Aug 1997, Martin Maechler wrote:

> This is a bug both in R and S-plus (in R it's "worse"), I think.

I don't think it's a bug

> Look at this :
> 
> ma <- cbind(1,1:8); logi <- rep(c(T,F),4)
> ma[logi,]
> ##>      [,1] [,2]
> ##> [1,]    1    1
> ##> [2,]    1    3
> ##> [3,]    1    5
> ##> [4,]    1    7
> 
> ##-- now the same with  [ , drop = FALSE]
> 
> ## R (-0.50-a3) :
> 
> 	 ma[logi, drop = F]
> ##>> Error: invalid subscript type
> ## Splus-3.4:
> 	 ma[logi, drop = F]
> ##>> [1] 1 1 1 1 1 3 5 7

This is correct.  Did you mean ma[logi,,drop=F]? If you use
ma[logi,drop=F] then this is the equivalent of ma[logi] with drop=F. But
ma[logi] treats the matrix as a vector and there aren't any dimensions to
drop. R should probably recycle the index vector the way S does. 

The loss of dimensions is unavoidable -- suppose you had
ma[c(3,7,8),drop=F].  How are you going to turn this into a matrix?


Thomas Lumley
------------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: R-0.50-a3: [logical, drop = FALSE] -- bug in R (and S-plus)
Thomas Lumley