我正在尝试为一个类定义一个新data
方法。foo
我的foo
对象遵循以下结构:
setClass(Class = "foo",
representation = representation(
data = "data.frame",
id = "character",
wl = "numeric"
)
)
data
我试图创建的方法实际上是访问@data
插槽的内容:
setMethod("data", "foo",
function(object)
object@data
)
我一直在查看编写 R 扩展手册的第 7.1 节,但它只处理 S3 类。我也看过这篇文章,但没有成功:
setGeneric("data", function(object, ...) standardGeneric('data'))
setMethod("data", "ANY", utils::data)
setMethod("data", "foo",
function(object)
object@data
)
加载包时:
> data(mtcars)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "data", for signature "data.frame"