S4设置< - 方法错误。没有现有的功能定义

时间:2017-09-28 18:14:13

标签: r methods s4

您好我正在尝试创建一个'子空间'类,它能够替换子空间类的数据值。我有以下但我仍然有错误。有人可以帮忙吗?

 65 # CLASS CREATION OF SUBSPACE
 66 #| 
 67 #| SUBSPACE CLASS                                                                               
 68 #| Nik Pocuca July 21th - 2017                                                                  
 69 #| Definition of subspace of dataspace class. Each subspace conatins the dataset with the       |
 70 #| referenced partition, and a coupled lexicon vector.                                          
 71 #|                                                                                              
 72 #| 
 73 subspace <- setClass(Class = "subspace",
 74 slots = c(
 75 data = "data.frame",
 76 vectors = "Lexicon Vector"
 77 ))
 78 
 79 
 80 # SETTING GENERICS FOR CLASSES
 81 setGeneric("updateSubspace", function(x)standardGeneric("updateSubspace"))
 82 
 83 setGeneric("updateSubspace<-", function(x, value)standardGeneric("updateSubspace<-"))
 84 
 85 
 86 # SETTING METHODS FOR ACCESSING INFORMATION
 87 setMethod("$", "subspace", function(x, name) {
 88     slot(x, name)
 89 })
 90 
 91 
 92 setMethod("updateSubspace", "subspace", function(x){
 93         x@data
 94 })
 95 
 96 # SETTING REPLACE METHOD FOR REPLACING INFO
 97 
 98 setReplaceMethod("updateSubspace",        c("subspace","data.frame"),function(x,newData) {
 99  x@data <- newData
 100  x
 101 })
 102 
 103 

我试图明白我能做到这一点。

 updateSubspace(partSpace) <- newData 

partSpace有一些价值。 partSpace $数据。

目前我收到此错误:

  Error in setMethod("updateSubspace", "subspace", function(x) { : 
  no existing definition for function ‘updateSubspace’
> sourceCode()
  Error in conformMethod(signature, mnames, fnames, f, fdef, 
 definition) : 
   in method for ‘updateSubspace<-’ with signature 
‘x="subspace",value="data.frame"’: formal arguments (value = 
"data.frame") omitted in the method definition cannot be in the 
signature

1 个答案:

答案 0 :(得分:0)

我明白了:

enter code here
#Generic is like prototyping apparently. 

setGeneric("updateSub", function(x,newData) 
standardGeneric("updateSub") )


# Setting Method 

setMethod("updateSub", function(x,newData) {
x@data <- newData
x
}