woobert
woobert

Reputation: 502

Using length() for a new class in R

I am trying to use the function length() on the class item to reveive the length of the vector options.

setClass(Class = "item",
  representation = representation(
    options = "character"
  ),
  prototype = prototype(
    options = character()
  )
)
setGeneric("length")
setMethod("length", signature(x = "item"), definition = function(x) length(x@options))

However, I always get the following error:

Error: could not find function "getGeneric"
Warning:
In .rk.get.structure.global(".__C__item") :
  failure to get object .__C__item

I am using R version 2.13.2 (2011-09-30) with RKWard Version 0.5.7z+0.5.8+devel1.

Upvotes: 1

Views: 802

Answers (1)

Richie Cotton
Richie Cotton

Reputation: 121067

By default, the methods package doesn't load at startup. Call

library(methods)

Upvotes: 1

Related Questions