I'm trying to define a new data
method for a foo
class. My foo
objects follow the following structure:
setClass(Class = "foo",
representation = representation(
data = "data.frame",
id = "character",
wl = "numeric"
)
)
The data
method I'm trying to create is actually accessing the contents of the @data
slot:
setMethod("data", "foo",
function(object)
object@data
)
I've been looking at the section 7.1 of the Writing R Extensions manual, but it only deals with S3 classes. I also had a peek at this post, but without success:
setGeneric("data", function(object, ...) standardGeneric('data'))
setMethod("data", "ANY", utils::data)
setMethod("data", "foo",
function(object)
object@data
)
When loading the package:
> data(mtcars)
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "data", for signature "data.frame"