From maechler at stat.math.ethz.ch  Mon Mar 14 13:57:16 2005
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon Mar 14 13:57:31 2005
Subject: [Rd] Use of htest class for different tests
In-Reply-To: <Pine.LNX.4.51.0503141338500.14878@artemis.imbe.med.uni-erlangen.de>
References: <7FFEE688B57D7346BC6241C55900E730B6FFA0@pollux.bfro.uni-lj.si>
	<Pine.LNX.4.51.0503141338500.14878@artemis.imbe.med.uni-erlangen.de>
Message-ID: <16949.35372.502952.997482@stat.math.ethz.ch>

>>>>> "Torsten" == Torsten Hothorn <Torsten.Hothorn@rzmail.uni-erlangen.de>
>>>>>     on Mon, 14 Mar 2005 13:43:32 +0100 (CET) writes:

    Torsten> On Sun, 13 Mar 2005, Gorjanc Gregor wrote:
    >> Hello!
    >> 
    >> First of all I must appologize if this has been raised
    >> previously, but search provided by Robert King at the
    >> University of Newcastle seems to be down these
    >> days. Additionally let me know if such a question should
    >> be sent to R-help.
    >> 
    >> I did a contribution to function hwe.hardy in package
    >> 'gap' during the weekend. That functions performs
    >> Hardy-Weinberg equilibrium test using MCMC. The return of
    >> the function does not have classical components for htest
    >> class so I was afcourse not successfull in using
    >> it. However, I managed to copy and modify some part of
    >> print.htest to accomplish the same task.
    >> 
    >> Now my question is what to do in such cases? Just copy
    >> parts of print.htest and modify for each test or anything
    >> else. Are such cases rare? If yes, then mentioned
    >> approach is probably the easiest.
    >> 

    Torsten> you can use print.htest directly for the components
    Torsten> which _are_ elements of objects of class `htest'
    Torsten> and provide your one print method for all
    Torsten> others. If your class `foo' (essentially) extends
    Torsten> `htest', a simple version of `print.foo' could by

   Torsten>  print.foo <- function(x, ...) {
   Torsten>  
   Torsten>     # generate an object of class `htest'
   Torsten>     y <- x
   Torsten>     class(y) <- "htest"
   Torsten>     # maybe modify some thinks like y$method
   Torsten>     ...
   Torsten>     # print y using `print.htest' without copying code
   Torsten>     print(y)
   Torsten>  
   Torsten>     # and now print additional information
   Torsten>     cat(x$whatsoever)
   Torsten>  
   Torsten>  }

and if you want to really `comply to standards'
you should end your print method with

    invisible(x)

Martin Maechler, ETH Zurich


[Rd] Use of htest class for different tests
Martin Maechler