[R] unable to find inherited method for function "edges", for signature "ugsh", "missing"

Søren Højsgaard Soren.Hojsgaard at agrsci.dk
Sun Apr 15 23:37:37 CEST 2007


I am new to using S4 methods and have run into this problem (on Windows XP using R 2.4.1): I am writing a package in which I use the graph package. I define my own classes of graphs as:
 
setOldClass("graphsh")
setOldClass("ugsh")
setIs("ugsh",  "graphsh")
 
(I know that I "should have" used setClass instead - and I will eventually - but right now I am just puzzled about the reason for my problem...) I need an 'edges' method for ugsh graphs, so I set:
 
if (!isGeneric("edges")) {
  if (is.function("edges")) 
    fun <- edges
  else 
    fun <- function(object,which) standardGeneric("edges")
  setGeneric("edges", fun)
}
setMethod("edges", signature(object = "graphsh"),
          function(object, which) {
            .links(object)
             })

I can get this to work in the sense that it passes R cmd check. However, if I add the following (to me innocently looking function) to my package I get problems:
 
nodeJoint <- function(bn, set, normalize=TRUE){
  vars <- set
  a    <- vallabels(gmd)[vars]
  levs <- as.data.frame(table(a))
  levs <- levs[,1:length(a)]
  levs2 <- do.call("cbind",lapply(levs, as.character))
  p<-sapply(1:nrow(levs2), function(i)
            pevidence(enterEvidence(bn, nodes=vars, states=levs2[i,]))
            )
  if (normalize)
    p <- p / sum(p)
  
  levs$.p <- p
  return(levs)
}

When running R cmd check I get:
> ug <- ugsh(c("me","ve"),c("me","al"),c("ve","al"),c("al","an"),c("al","st"),c("an","st"))
> edges(ug)
Error in function (classes, fdef, mtable)  :
        unable to find an inherited method for function "edges", for signature "ugsh", "missing"
Execution halted

(I never use the function nodeJoint in my .Rd files, so it just "sits there"  and causes problems. 
 
I am puzzled about what the error message means and about why this function causes problems. Can anyone help. Thanks in advance.
 
Søren



More information about the R-help mailing list