[R] printing all htest class members

William Dunlap wdunlap at tibco.com
Thu Dec 15 22:47:20 CET 2011


I think you should subclass "htest" and write a print method
for that subclass.  E.g.,

  > print.htest_rb <- function(x, ...) {
  +    NextMethod(x, ...)
  +    cat("all.orders =", x$all.orders, "\n")
  +    invisible(x)
  + }
  > ht2$all.orders <- "THIS IS THE 'all.orders' COMPONENT"
  > class(ht2) <- c("htest_rb", class(ht2))
  > ht2
  
          Test the 'print.htest' method
  
  data:  x 
  Q = 0.0129, df = 2, p-value = 0.9936
  alternative hypothesis: It doesn't print 'all.orders' 
  null values:
    ord df      Q      p
  1   2  2 0.0129 0.9936
  2   3  3 0.0490 0.9972
  3   4  4 0.0684 0.9994
  
  all.orders = THIS IS THE 'all.orders' COMPONENT

If you want the 'all.order' information printed in the
middle of the htest printout then you will have to copy
the code in stats:::print.htest to your print.htest_rb
method and edit it to suit you.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rui Barradas
> Sent: Thursday, December 15, 2011 12:12 PM
> To: r-help at r-project.org
> Subject: Re: [R] printing all htest class members
> 
> 
> Hello,
> 
> Once again, and as simple as possible,
> 
> res <- data.frame(ord=2:4, df=2:4, Q=c(0.0129, 0.049, 0.0684),
>                     p=c(0.9936, 0.9972, 0.9994))
> 
> ht2<-structure(
>     list(statistic=c(Q=res$Q[1]),
>         p.value=res$p[1],
>         parameter=c(df=res$df[1]),
>         alternative="It doesn't print 'all.orders'",
>         method="Test the 'print.htest' method",
>         data.name=deparse(substitute(x)),
>         null.value=res      # this is printed
>         #all.orders=res     # this wouldn't be if uncommented
>     ),
>     .Names=c("statistic","p.value","parameter","alternative",
>             "method","data.name","null.value"),
>     class="htest"
> )
> ht2
> class(ht2)
> 
> Creation? Conversation in my head? Have you heard about the experimental
> method?
> It's a very usefull device created by one Galileo Galilei some time ago.
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/printing-all-htest-class-members-
> tp4200872p4201793.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list