[Rd] breaking my "length" method also breaks str()

From: Herve Pages <hpages_at_fhcrc.org>
Date: Wed, 26 Sep 2007 18:01:19 -0700


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)

But if my "length" method is broken, then str() stops working:

> setMethod("length", "A", function(x) length(x@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 :-/


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 27 Sep 2007 - 01:03:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Sep 2007 - 02:42:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.