総称関数で,たとえば print は以下のように多数ある.
> methods(print) [1] print.acf* [2] print.anova [3] print.aov*
アスタリスクが付いているメソッドは,関数を直接確認できないことがある.namespase が分かれば :: を使って
> TukeyHSD
function (x, which, ordered = FALSE, conf.level = 0.95, ...)
UseMethod("TukeyHSD")
<bytecode: 0x24d9e08>
<environment: namespace:stats>
> stats::TukeyHSD
function (x, which, ordered = FALSE, conf.level = 0.95, ...)
UseMethod("TukeyHSD")
<bytecode: 0x24d9e08>
<environment: namespace:stats>
::: を使うと,関数本体を確認できる
> stats:::print.TukeyHSD
function (x, digits = getOption("digits"), ...)
{
cat(" Tukey multiple comparisons of means\n")
cat(" ", format(100 * attr(x, "conf.level"), 2),
"% family-wise confidence level\n",
sep = "")
if (attr(x, "ordered"))
cat(" factor levels have been ordered\n")
cat("\nFit: ", deparse(attr(x, "orig.call"), 500), "\n\n",
sep = "")
xx <- unclass(x)
attr(xx, "orig.call") <- attr(xx, "conf.level") <- attr(xx,
"ordered") <- NULL
xx[] <- lapply(xx, function(z, digits) {
z[, "p adj"] <- round(z[, "p adj"], digits)
z
}, digits = digits)
print.default(xx, digits, ...)
invisible(x)
}
<bytecode: 0x2700660>
<environment: namespace:stats>
最初から
getS3method (f = "print", class = "TukeyHSD")
とする方法もあります.