[R] S4 "["-method called twice - why?

Mark Heckmann mark.heckmann at gmx.de
Wed Dec 8 12:41:01 CET 2010


Dear list,

When playing around with the "[" method for S4 classes I noticed that it gets called twice in my example.

setClass("testClass", 
		 representation(a="character"))
	
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
        function (x, i, j, ..., drop){
            print("void function")
        }
)

> x <- new("testClass")
> x[1]
[1] "void function"
[1] "void function"
> x[1,1]
[1] "void function"
[1] "void function"
> x[1,1,1]
[1] "void function"
[1] "void function"
> 

Why is that so? Can someone help me understand the logic behind it?

Thanks,
Mark

–––––––––––––––––––––––––––––––––––––––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com



More information about the R-help mailing list