您好,我正在尝试创建一个能够替换子空间类数据值的“子空间”类。我有以下内容,但仍然出现错误。谁能帮忙?
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 有一些值。部分空间$数据。
目前我收到这个错误:
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
最佳答案
我想通了:
#Generic is like prototyping apparently.
setGeneric("updateSub", function(x,newData)
standardGeneric("updateSub") )
# Setting Method
setMethod("updateSub", function(x,newData) {
x@data <- newData
x
}
关于r - S4 设置 <- 方法错误。没有现有的函数定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46475787/