Class 对R中的新类使用length()

Class 对R中的新类使用length(),class,r,Class,R,我试图使用类项上的函数length()来显示向量选项的长度 setClass(Class = "item", representation = representation( options = "character" ), prototype = prototype( options = character() ) ) setGeneric("length") setMethod("length", signature(x = "item"), definiti

我试图使用类
上的函数
length()
来显示向量
选项的长度

setClass(Class = "item",
  representation = representation(
    options = "character"
  ),
  prototype = prototype(
    options = character()
  )
)
setGeneric("length")
setMethod("length", signature(x = "item"), definition = function(x) length(x@options))
但是,我总是遇到以下错误:

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

我正在使用
R版本2.13.2(2011-09-30)
和RKWard版本0.5.7z+0.5.8+devel1。

默认情况下,启动时不会加载
方法。召唤

library(methods)

默认情况下,启动时不会加载
方法
包。召唤

library(methods)

奇怪的是,它对我来说很好(R2.13.1)好的,RKWard版本0.5.7z+0.5.8+devel1似乎有问题。代码在普通的R shell中运行没有困难。
methods::setGeneric
/
methods::setMethod
,因为RKWard太聪明了?那么我建议您切换到RStudio或伟大的组合Eclipse/StatET:-)这很奇怪,它对我来说很好(R2.13.1)好,RKWard版本0.5.7z+0.5.8+devel1似乎有问题。代码在普通的R shell中运行没有困难。
methods::setGeneric
/
methods::setMethod
,因为RKWard太聪明了?那么我建议您切换到RStudio或伟大的组合Eclipse/StatET:-)嗯,这并没有什么好处difference@woobert它是有线的。我也有同样的情况,但这对我来说很有效。嗯,那没什么大不了的difference@woobert它是有线的。我也有同样的情况,但这对我很有效。