R-alpha: 'Matrix' & 'matrix' Class

Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at
Wed, 13 Aug 1997 10:23:43 +0200


>>>>> Thomas Lumley writes:

>> 
>> I disagree (I think this is a rare thing with you Thomas..).
>> ----------
>> 1) Lest I misunderstood something,
>> you mean that	for matrices 'x',
>> x[,1]
>> would be a 1--column matrix instead of a vector ?
>> IMHO, this is ugly, and is really just logical if you come from a strict
>> matrix thinker's corner which is the case for  matlab users, and maybe even
>> mathematicians and the like (I'm one myself),
>> but not for an average person analyzing  statistical data.

> I'm not opposed to a matrix class, but I do think drop=FALSE should be
> the default for arrays (I'm not as sure about data frames, but I do
> think it is reasonable that one row of a data frame should be a data
> frame). The reason is that the *current* behaviour of [ with drop=TRUE
> in S and R breaks a lot of S code.

> I have found this particular problem in code written for other people
> to use by people from a wide range of backgrounds. For example, Harald
> Fekjaer's addreg library, Adrian Raftery's bayesian model averaging
> code, and even an early version of Brian Ripley's linear
> discrimination function. These functions break because they assume
> that x[vec,] is a matrix even when it has a single row.  It rarely
> seems to matter if x[,1] is a matrix or a vector, but it is important
> if x[1,] is a vector.

(Hmm.  Why do they break subsequently?)

> For data analysis I don't think it matters much, though I agree it is
> a little ugly for x[,1] to be a matrix. For programming I think that
> drop=F is the same sort of incompatibility as the R scoping rules: one
> that fixes, rather than breaks, S code. Of course people could just
> use drop=F, the way they could just pass variables into nested
> functions explicitly.  The problem is that most of us don't, and it's
> a remarkably difficult bug to find.

I have two remarks on this one.

* Thomas, if you have ports of the above software, could you PLEASE
package them?  (Btw, I have a finished `port' of the V&R `classif'
library, and of the `clus' library which comes with the paper on JSS.)

* Personally, I feel that x[1,] and x[,1] should be a vector if x is a
matrix.  As Martin said, MATRIX `freaks' should be able to attach class
attribute Matrix which would give drop = F.  (Fortunately, the S lang
does not have scalars, otherwise we'd we in trouble with x[i] for x a
vector ...).

If that breaks existing code, I think we should try to get the authors
of that code to make compatibility changes if possible.  E.g. in the
above cases, if subscripting with drop = F would do the trick in either
case, then I don't think that e.g. V&R would object to making the
change.

Or, perhaps R&R should ask Chambers why S does things the way it does?

Best,
-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-