|
许多泛形函数的函数主体部分非常的短,如
> coef
function (object, ...)
UseMethod("coef")
UseMethod 的出现暗示着这是一个泛形函数。 为了查看那些方法可以使用,我们可以使用函数methods()
> methods(coef)
[1] coef.aov* coef.Arima* coef.default* coef.listof*
[5] coef.nls* coef.summary.nls*
Non-visible functions are asterisked
这个例子中有六个方法,不过其中任何一个都不能简单地通过键入名字来查看。我们可以通过下面两种方法查看这种方法
> getAnywhere("coef.aov")
A single object matching ’coef.aov’ was found
It was found in the following places
registered S3 method for coef from namespace stats
namespace:stats
with value
function (object, ...)
{
z <- object$coef
z[!is.na(z)]
}
> getS3method("coef", "aov")
function (object, ...)
{
z <- object$coef
z[!is.na(z)]
}
|
|