在为新类创建新方法时遇到错误
> setClass(“CIR”,表示(PATH =“numeric”,GRID =“numeric”,PARAMS =“numeric”));
[1]“CIR”
>
> setMethod(“plot”,signature(x =“CIR”),,, + function(x){
+ plot(slot(x,“GRID”),slot(x,“PATH”),type =“l”)
+点(槽(x,“GRID”),槽(x,“PATH”),col =“红色”,cex = 0.5)
+})
as.environment(where)中的错误:'as.environment'的无效对象
我该如何解决?谢谢!
答案 0 :(得分:2)
在包含setMethod
的行末尾有两个逗号,这意味着您无意中将definition
留空并将where
设置为函数。试试这个:
setMethod("plot", signature(x="CIR"),
function(x) {
plot(slot(x,"GRID"),slot(x,"PATH"),type="l")
points(slot(x,"GRID"),slot(x,"PATH"),col="red",cex=0.5)
})