如何修补R包中的S4方法?

时间:2010-05-14 15:29:08

标签: r s4 gwidgets

如果您发现包中存在错误,通常可以使用fixInNamespace修补问题,例如fixInNamespace("mean.default", "base")

对于S4方法,我不知道怎么做。我正在查看的方法是在gWidgetstcltk包中。您可以使用

查看源代码
getMethod(".svalue", c("gTabletcltk", "guiWidgetsToolkittcltk"))

我找不到fixInNamespace的方法。

fixInNamespace(".svalue", "gWidgetstcltk")

Error in get(subx, envir = ns, inherits = FALSE) : 
  object '.svalue' not found

我认为setMethod可以解决问题,但

setMethod(".svalue", c("gTabletcltk", "guiWidgetsToolkittcltk"),
  definition = function (obj, toolkit, index = NULL, drop = NULL, ...) 
  {
      widget = getWidget(obj)
      sel <- unlist(strsplit(tclvalue(tcl(widget, "selection")), 
          " "))
      if (length(sel) == 0) {
          return(NA)
      }
      theChildren <- .allChildren(widget)
      indices <- sapply(sel, function(i) match(i, theChildren))
      inds <- which(visible(obj))[indices]
      if (!is.null(index) && index == TRUE) {
          return(inds)
      }
      if (missing(drop) || is.null(drop)) 
          drop = TRUE
      chosencol <- tag(obj, "chosencol")
      if (drop) 
          return(obj[inds, chosencol, drop = drop])
      else return(obj[inds, ])
  },
  where = "package:gWidgetstcltk"  
)

Error in setMethod(".svalue", c("gTabletcltk", "guiWidgetsToolkittcltk"),  : 
  the environment "gWidgetstcltk" is locked; cannot assign methods for function ".svalue"

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

老派获取资源,应用变更和重建的方式怎么样?