From wdunlap at tibco.com  Tue Nov 11 22:12:33 2008
From: wdunlap at tibco.com (William Dunlap)
Date: Tue, 11 Nov 2008 13:12:33 -0800
Subject: [Rd] is.matrix
In-Reply-To: <f8e6ff050811111203m5e21f74fy60d24604c3c4b72c@mail.gmail.com>
References: <d8858f220811111020j233d4d98j502c0079ace644e7@mail.gmail.com><4919D240.4040904@acm.org><f8e6ff050811111121u62cc1329s605ca0dcd521dfb2@mail.gmail.com><4919E010.8080603@idi.ntnu.no><f8e6ff050811111148m773ec9d3x22cbabd8efa8b51c@mail.gmail.com><4919E400.9090707@idi.ntnu.no>
	<f8e6ff050811111203m5e21f74fy60d24604c3c4b72c@mail.gmail.com>
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70028D7F6@NA-PA-VBE03.na.tibco.com>

S+, now and as far back as 3.4 (1996) and S versions 3 (c. 1990)
and 4 (1999) define is.matrix as
   function(x)length(dim(x)) == 2
so is.matrix(data.frame(x=1:3,y=4:6)) returns TRUE.
It essentially means that you can use 2 subscripts on
the object (it assumes that the dim() method for class(x)
is defined appropriately).

We never changed it to look at the S4 class or the dim attribute
directly because that broke old code.

Why do people call is.matrix(x)?

Bill Dunlap
TIBCO Spotfire Inc
wdunlap tibco.com  

> -----Original Message-----
> From: r-devel-bounces at r-project.org 
> [mailto:r-devel-bounces at r-project.org] On Behalf Of hadley wickham
> Sent: Tuesday, November 11, 2008 12:03 PM
> To: Wacek Kusnierczyk
> Cc: r-devel at r-project.org
> Subject: Re: [Rd] is.matrix
> 
> On Tue, Nov 11, 2008 at 1:58 PM, Wacek Kusnierczyk 
> <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
> > hadley wickham wrote:
> >> On Tue, Nov 11, 2008 at 1:42 PM, Wacek Kusnierczyk 
> >> <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no> wrote:
> >>
> >>> hadley wickham wrote:
> >>>
> >>>>> |  is.matrix| returns |TRUE| if |x| is a matrix and has a |dim 
> >>>>> | <dim.html>|
> >>>>> attribute of length 2) and |FALSE| otherwise
> >>>>>
> >>>>>
> >>>> That's confusing!  In what situations is x a matrix but does not 
> >>>> have a dim attribute?
> >>>>
> >>>>
> >>>>
> >>> x = matrix(1,1,1)
> >>> dim(x) = c(1,1,1)
> >>>
> >>
> >> I think you meant
> >> dim(x) <- c(3, 1)
> >>
> >> You created a 1 x 1 x 1 array.
> >>
> >
> > i know, that's precisely what i wanted.  this is a simple 3d 
> > structure, yet is(x) reveals it is a matrix.  that was the point.
> 
> I think the message here is not to use is().  is() is 
> designed for use with S4 objects, and it doesn't always give 
> what you'd expect for primitive objects.  This isn't normally 
> a problem because for those objects you use is.matrix(), 
> is.array(), is.vector() etc.  Sure, this isn't a particularly 
> wonderful aspect of the language, but there are far more 
> interesting and important things for people to spend their 
> time on, and fixing these behaviours now could potentially 
> break large amounts of existing code, with little benefit.
> 
> Hadley
> 
> 
> --
> http://had.co.nz/
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] is.matrix
William Dunlap