[Rd] breaking my "length" method also breaks str()
Herve Pages
hpages at fhcrc.org
Thu Sep 27 03:01:19 CEST 2007
Hi,
This works fine and gives 26:
setClass("A", representation(bidule="character"))
setMethod("length", "A", function(x) length(x at bidule))
a <- new("A", bidule=letters)
str(a)
length(a)
But if my "length" method is broken, then str() stops working:
> setMethod("length", "A", function(x) length(x at bidulle))
> str(a)
Error in length(object) :
no slot of name "bidulle" for this object of class "A"
Doesn't seem like a big deal on such a simple example but this can be
really problematic. I already had the situation where the "length" method
is in fact very complicated, with a lot of nested calls and one access to
a database and an error occurring at a deep level. I noticed that my program
had a problem but I was not yet aware that "length" was broken. So I started
the debug session and tried to use str() to look inside my objects... but
str() was not working! Which makes a debugging session with a lot of S4 stuff
all around the place quite painful :-/
Cheers,
H.
More information about the R-devel
mailing list