[R] unable to find inherited method for function "edges", for signature "ugsh", "missing"
Seth Falcon
sfalcon at fhcrc.org
Mon Apr 16 02:04:11 CEST 2007
Søren Højsgaard <Soren.Hojsgaard at agrsci.dk> writes:
> 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...)
It isn't clear that your problems aren't being caused by your
non-standard approach to defining classes and I would recommend you
fix this part of your code first.
If you are depending on the graph package, I'm surprised you don't
want to extend one of the graph classes there. Perhaps:
setClass("graphsh", contains="graph")
Or
setClass("graphsh", contains="graphNEL")
You can override whatever methods you need to, but don't have to write
new methods for those that work as you want.
> 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)
> })
Do you want to have your own generic distinct from the edges generic
defined in the graph package or do you want to simply attach new
methods to the edges generic defined in graph. I see no benefit to
this conditional approach and it _can_ cause confusion.
> 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]
^^^
Where is that defined?
> 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)
> }
I can't see where a call to edges is made. Is there one hiding in one
of the function calls?
> 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.
Does your package have a name space? What does your package's
DESCRIPTION file look like? Do any of the examples call library() or
require()?
+ seth
--
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org
More information about the R-help
mailing list