Reputation: 518
I wrote an R package which fits a statistical model, say of class class
. I want to write my own summary method summary.class
in the style of summary.lm
.
I am confused how to produce such a summary output. My model of class class
is a list which, e.g., contains the element pvalue = 0.05
. Do I use cat
in summary.class
to print the p-value? How to properly format multiple outputs of this kind in a table?
summary.lm
does not seem to contain any print
or cat
command.
summary.class = function(obj,...){
cat(obj$pvalue)
}
Upvotes: 1
Views: 955
Reputation: 61953
A typical approach when writing summary functions is to gather all the info you want, create an object with all of that information, give that object a new class (probably something like summary.yourclass), and then return the object. Ultimately you would then need to write a new function that does print.summary.yourclass. Inside of that print function you probably would make some calls to cat or something similar.
Upvotes: 4