2010-05-14 32 views
0

如果發現軟件包中存在錯誤,通常可以使用fixInNamespace(例如, fixInNamespace("mean.default", "base")如何在R包中修補S4方法?

對於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" 

任何想法?

+0

我會建議將補丁提交給軟件包作者。 – Shane 2010-05-14 15:37:05

+0

@Shane:我已經完成了,但我很不耐煩,想立即看到更改後的版本。 – 2010-05-16 09:12:03

回答

1

古老的方式獲取源,應用變化和重建如何?

+0

我有一種感覺,這可能是唯一的答案。雖然看起來很費力。 – 2010-05-16 09:14:33