[BioC] bug in graph::addNode() w/ graph::edgeData()

Robert Castelo robert.castelo at upf.edu
Thu Nov 7 16:04:20 CET 2013


i have found a problem when using the functions addNode() and edgeData() 
from the graph package, which i believe is a bug and it can be 
reproduced with the following minimal example:


## build a graphBAM object with vertices a, b, d, e and edges a-d, b-e
df <- data.frame(from=c("a", "b"),
                  to  =c("d", "e"),
                  weight=rep(1, 2))
g <- graphBAM(df)
[1] "a" "b" "d" "e"

## add a numerical attribute to one of the edges
edgeDataDefaults(g, "x") <- NA_real_
edgeData(g, from="a", to="d", "x") <- 1
unlist(edgeData(g, attr="x"))
a|d b|e d|a e|b
   1  NA   1  NA

## add an extra node f to the graphBAM object and fetch edge attributes
gOK <- addNode("f", g)
[1] "a" "b" "d" "e" "f"
unlist(edgeData(gOK, attr="x"))
a|d b|e d|a e|b
   1  NA   1  NA

## now comes the bug ...

## add an extra node c to the graphBAM object and fetch edge attributes
gBUG <- addNode("c", g)
[1] "a" "b" "c" "d" "e"
unlist(edgeData(gBUG, attr="x"))
Error in data.frame(ft, tmp, stringsAsFactors = FALSE) :
   arguments imply differing number of rows: 4, 6
7: stop(gettextf("arguments imply differing number of rows: %s",
        paste(unique(nrows), collapse = ", ")), domain = NA)
6: data.frame(ft, tmp, stringsAsFactors = FALSE)
5: .eAttrsFun(self, from = names(edges(self)), attr = attr)
4: as.list(.eAttrsFun(self, from = names(edges(self)), attr = attr))
3: edgeData(gBUG, attr = "x")
2: edgeData(gBUG, attr = "x")
1: unlist(edgeData(gBUG, attr = "x"))

from this output, my guess is that the problem is related to the first 
line of code of the addNode() method in the R/methods-graphBAM.R file:

         signature(node="character", object="graphBAM", edges="missing"),
         function(node, object) {

             nds <- sort(unique(c(nodes(object), node)))

because if i simply remove the call to the function sort, i.e., 
replacing this line by

             nds <- unique(c(nodes(object), node))

then the problem is solved. however, i don't know whether this has other 
consequences related to the design of the package. upfront, i do not see 
a reason why, internally to the package, vertices should be 
alphabetically ordered.

best regards,
ps: sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

  [1] LC_CTYPE=en_US.UTF8       LC_NUMERIC=C 
  [9] LC_ADDRESS=C              LC_TELEPHONE=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] graph_1.40.0   vimcom_0.9-91  setwidth_1.0-3 colorout_1.0-1

loaded via a namespace (and not attached):
[1] BiocGenerics_0.8.0 parallel_3.0.2     stats4_3.0.2       tools_3.0.2

More information about the Bioconductor mailing list