Nik P
Nik P

Reputation: 145

S4 Setting <- Method Errors. No Existing Definition of function

Hi I am trying to create a 'subspace' class with the ability to replace the data value of the subspace class. I have the following but I am still getting errors. Can anyone help?

 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 

I am trying to get the point where i can do this.

 updateSubspace(partSpace) <- newData 

Where partSpace has a some value. partSpace$data.

Currently I am getting this error:

  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

Upvotes: 4

Views: 2795

Answers (1)

Nik P
Nik P

Reputation: 145

I figured it out:

#Generic is like prototyping apparently. 

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


# Setting Method 

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

Upvotes: 7

Related Questions