Skip to content
Prev 36214 / 63424 Next

Strange behavior of assign in a S4 method.

Dear Christophe

type

showMethods("foo1", inc=TRUE)
showMethods("foo2", inc=TRUE)

to see the difference between the two functions, and this will explain 
their different behaviour. This feature of S4 has been discussed here 
many times before, see e.g.: 
http://tolstoy.newcastle.edu.au/R/e4/help/08/01/1676.html

Perhaps juggling with the 'n' argument of 'parent.frame' could help in 
hacking something together that 'works', but as far as I can see what 
you want to is an abuse of R's pass by value / functional language 
semantics.

For example, try these and check whether this results in what you intended:

foo2(3)
foo2(e+2)
sapply(1:5, foo2)
ls()

	Best wishes
	Wolfgang


Christophe Genolini scripsit 15/03/10 11:33:
--
Wolfgang Huber
EMBL
http://www.embl.de/research/units/genome_biology/huber/contact