Skip to content

S4 "["-method called twice - why?

3 messages · Mark Heckmann, jim holtman

#
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")
        }
)
[1] "void function"
[1] "void function"
[1] "void function"
[1] "void function"
[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
#
I don't think it is being called twice; you are seeing the return
value printed out:
+                 representation(a="character"))
[1] "testClass"
+        function (x, i, j, ..., drop){
+            print("void function")
+            return(NULL)
+        }
+ )
[1] "["
[1] "void function"
NULL

        
On Wed, Dec 8, 2010 at 6:41 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote: