Skip to content

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

2 messages · Martin Maechler, Thomas Lumley

#
This is a bug both in R and S-plus (in R it's "worse"), I think.
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

##---- which is not correct either, we would want the matrix !
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
On Wed, 20 Aug 1997, Martin Maechler wrote:

            
I don't think it's a bug
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-