Can someone help me understand the following behavior of "[<-" ?
If I define a simple class based on a matrix, the [<- operation only
inserts into the first column:
> x <- matrix(rnorm(10),nrow=5,ncol=2)
> class(x) <- "foo"
> "[<-.foo" <- function(x, i, j, value) {
+ if(missing(i)) i <- 1:n
Try this:
x <- matrix(rnorm(10),nrow=5,ncol=2)
class(x) <- "foo"
"[<-.foo" <- function(x, i = TRUE, j = TRUE, ..., value) {
x <- unclass(x)
x <- NextMethod()
class(x) <- "foo"
x
}
x[] <- 100.0
On 9/22/06, Armstrong, Whit <[EMAIL PROTECTED]> wrote:
> Can someone help me unde
I've not seen an actual answer to this, which is that this is a
misunderstanding as to how NextMethod works.
First,
> + x <- unclass(x)
looks wrong. NextMethod uses the next method at the call to the generic,
and subsequent changes to the object 'x' do not alter the class that would
be d