在R中使用s4方法

时间:2018-07-12 12:09:40

标签: r s4 generic-method

我创建了以下S4类和方法:

setClass(
Class="simulateSpectra",
representation( nbPixel         = "numeric"
              , nbCluster     = "numeric"
              , nbSpectrum    = "numeric"
              , nbSampling    = "numeric"

 ),
prototype( nbPixel        = 1000
         , nbCluster    = 15
         , nbSpectrum   = 10
         , nbSampling   = 33
    ),
)
setGeneric("simulate",
       def=function(Object)
       {
         standardGeneric("simulate")
       }
 )
 setMethod(
 f = "simulate",
 signature = "simulateSpectra",
definition=function(Object)
{
  mean=function(t, nbSpectrum, nbCluster)
    {
      res <- array(0, c(nbCluster, nbSpectrum, length(t)));
      res
    }
 times = c(0,10,20,30)
 means <- mean(times, Object@nbSpectrum, Object@nbCluster)
 #do some computation

 Object@result = list(means)
 }
 )

我使用创建对象 obj = new("simulateSpectra"),然后通过simulate(obj)

将函数应用于对象

但是,出现以下错误: Error in mean(times, Object@nbSpectrum, Object@nbCluster) : no slot of name "times" for this object of class "simulateSpectra"

我不能在S4方法中使用临时变量times吗?

0 个答案:

没有答案