kummerer94
kummerer94

Reputation: 171

How can I implement the length function for S4 classes?

I want to implement the length() function in R for S4 class instances. I would have a class:

setClass("A", slots = c(ll = "list"))

Then, I want to create an instance inst of class A and call length(inst).

My previous attempts have failed and so far I could only find a way to do this for S3 classes. (Like the Formula package does here.)

Upvotes: 0

Views: 112

Answers (1)

Akindele Davies
Akindele Davies

Reputation: 399

Assuming you just want your length() method to delegate to the slot "ll".

setMethod("length", signature = "A", definition = function(x) length(x@ll))

Upvotes: 2

Related Questions