[R] Stumped on methods

Liaw, Andy andy_liaw at merck.com
Fri Jul 16 14:41:27 CEST 2004


Jim,

As Uwe said, that's not what NextMethod() is for.  I suspect what you really
want is simply cat()ing the object that you created in your print() method.
If you look in must print() and summary() methods, you'll see a lot of
cat().

HTH,
Andy

> From: Uwe Ligges
> 
> Jim Lemon wrote:
> 
> > I have been trying to write a "proper" print method for a 
> package, and have 
> > almost gotten what I want. From a reading of the relevant 
> section in R 
> > Extensions and the introduction to methods, I've stuck the 
> whole business 
> > into a character object and used:
> > 
> > NextMethod("print")
> 
> Well, it depends.
> If you have some inheritance of classes, you may reallay want to use 
> NextMethod(), but that's not necessary if you want to write your own 
> print method print.myclass() to print stuff that is not from any 
> superclass....
> Check out how to write methods in, e.g., Venables and Ripley 
> (2000): "S 
> Programming", Springer.
> 
> Uwe Ligges
> 
> 
> 
> > However, instead of not printing quotes and displaying the usual 
> > representation of the string, I get the whole string, 
> newlines and all, in 
> > quotes. My attempt to shamelessly copy someone else's print method 
> > was foiled as most of them don't display when one types the 
> function name. I 
> > presume this is a feature of namespaces.
> > 
> > Needless to say, searching the archives for "print & 
> method" retrieved a 
> > cornucopia of useless information. I wonder if anyone would 
> be kind enough to 
> > inform me where to look for the proper incantation? Thanks.
> > 
> > RedHat EL3 L:inux
> > R-1.9.1
> > Last.Drink - Aurora Expresso
> > 
> > Jim
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list