R - 向类添加方法

时间:2018-03-23 15:21:42

标签: r

我正在尝试向类添加方法:

setClass("cox.boost", slots=c(CoxBoost="CoxBoost"))
setGeneric("predictSurvProb", function(object) standardGeneric("predictSurvProb"))
  setMethod("predictSurvProb", signature(object="cox.boost"), function(object) predict(object=object, newdata=NULL, newtime=NULL, newstatus=NULL, type="risk", times=NULL))
>   setGeneric("predictSurvProb", function(object) standardGeneric("predictSurvProb"))
[1] "predictSurvProb"
>   setMethod("predictSurvProb", signature(object="cox.boost"), function(object) predict(object=object, newdata=NULL, newtime=NULL, newstatus=NULL, type="risk", times=NULL))
[1] "predictSurvProb"
> findMethods("cox.boost")
list()
Warning message:
In findMethods("cox.boost") :
  non-generic function 'cox.boost' given to findMethods()

该方法未添加到类中。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

要查看类的方法,可以使用以下命令:

methods(class = "cox.boost")

findMethods将用于泛型,即:

findMethods("predictSurvProb")