[Rd] More strange [[ behaviour

Herve Pages hpages at fhcrc.org
Mon Oct 2 21:21:31 CEST 2006


Hi,

> setClass("MyList", "list")
[1] "MyList"
> a <- new("MyList")
> a
An object of class "MyList"
list()
> setMethod("[[", "MyList", function(x, i, j, ...) cat("Just testing\n"))
> a[[]]
Just testing
> a[[1]]
Just testing
> a[[a=1]]
Just testing
> a[[b=1]]
Just testing
...
> a[[v=1]]
Just testing
> a[[w=1]]
Just testing
> a[[x=1]]
Error in a[[x = 1]] : subscript out of bounds
> a[[y=1]]
Just testing
> a[[z=1]]
Just testing

Can someone explain me why the "[[x=1]]" case is treated differently?

Cheers,
H.




More information about the R-devel mailing list