Skip to content

matrix subsetting (was: [R] as(obj,

1 message · Gabor Grothendieck

#
Suggest you try R 1.9.1 patched.  This is what I get on 
Windows XP with that:
[1] 1 2
[1] 1 2
no object named '[.matrix' was found
no object named '[.foo' was found
Error in args("[.matrix") : couldn't find function "[.matrix"
Error in get(x, envir, mode, inherits) : variable "[.matrix" of mode "function" was not found
[1] "R version 1.9.1, 2004-07-13"







Date:   	Thu, 29 Jul 2004 21:46:27 +0100
From:   	Patrick Burns <pburns@pburns.seanet.com>
To:   	John Chambers <jmc@research.bell-labs.com>, <r-devel@stat.math.ethz.ch>
Subject:   	[Rd] Re: matrix subsetting (was: [R] as(obj,"matrix"))

On a related topic, a client came up with this example
a few days ago which I was unable to explain. (But he
did heed my advise of "don't do that".)
Testing
[,1] [,2]
[1,] 1 3
[2,] 2 4
attr(,"class")
[1] "foo"
[1] 1 2
function(x, i, j, drop = if(missing(i)) TRUE else length(cols)==1)
{
cat("Testing\n")
x
}
function(x, i, j, drop = if(missing(i)) TRUE else length(cols)==1)
{
cat("Testing\n")
x
}

Everything is the same except for the name of the class. When
the class is "matrix", it ignores the subset method. But the very
same code works if the class is "foo". This is 1.9.1 Windows,
and the same happens with 1.7.0 (the oldest version I have on
my machine).

What is happening here?


Patrick Burns

Burns Statistics
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
John Chambers wrote: