[Rd] Bug in str or issue with class management in my package?

Martin Morgan mtmorgan at fhcrc.org
Fri Mar 23 14:01:04 CET 2007


Ulrike,

booteval.relimp has the statement

    ausgabe <- calc.relimp(empcov, type = type, diff = diff, 
        rank = rank, rela = rela, always = always, groups = groups, 
        groupnames = groupnames)
    class(ausgabe) <- "relimplmbooteval"

This changes the name of the class of ausgabe, without changing its
structure. I'm guessing that prior to this call ausgabe did not have a
slot "pmvd.lower". Here's the simpler version:

>setClass("A", representation=representation(x="numeric"))
[1] "A"
> setClass("B", contains="A", representation=representation(y="numeric"))
[1] "B"
> a <- new("A")
> class(a) <- "B"
> str(a)
Error in FUN(c("y", "x")[[1L]], ...) : no slot of name "y" for this object of class "B"

and some behavior which is somehow weird:

> slot(a, "y")
Error in slot(a, "y") : no slot of name "y" for this object of class "B"
> slot(a, "y") <- 10 # 'creates' the slot!
> slot(a, "y")
[1] 10

Probably what you want to do is to create a 'setAs' method

setAs('relimplm', 'relimplmbooteval',
      function(from) {
          <your code here, e.g.,>
      })

and use

    ausgabe <- as(ausgabe, "relimplmbooteval")

I'm not really sure what <your code here> should look like; my first
stab was

          obj <- new("relimplmbooteval")
          slots <- slotNames(from)
          for (slt in slots)
              slot(obj, slt) <- slot(from, slt)
          obj

which would not be very memory efficient (each slot assignment copies
the entire object) but is perhaps fine for your needs.

Hope that helps

Martin

Ulrike Grömping <groemp at tfh-berlin.de> writes:

> Dear developeRs,
>
> with R 2.4.1 (and also 2.4.0), the function str() fails on objects of class
> relimplmbooteval, if there are unused slots, which is very often the case. I
> am not sure whether this is a bug in str() or a correct behavior of str()
> that unmasks some sloppiness in my usage of S4 classes (that I am not aware
> of)?
>
> Reproducible example (package relaimpo needed):
>
> The program 
>
> require(relaimpo)
> bte<-booteval.relimp(boot.relimp(swiss,b=100))
> str(bte)
>
> yields the error message
>
> Errorr in FUN(c("lmg.lower", "lmg.upper", "lmg.rank.lower",
> "lmg.rank.upper",  : 
>         no slot named "pmvd.lower" for this object of class
> "relimplmbooteval"
> (back-translated from German).
>
> Regards, Ulrike
> -- 
> View this message in context: http://www.nabble.com/Bug-in-str-or-issue-with-class-management-in-my-package--tf3453429.html#a9633559
> Sent from the R devel mailing list archive at Nabble.com.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Martin Morgan
Bioconductor / Computational Biology
http://bioconductor.org



More information about the R-devel mailing list