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

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


hi,

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:

library(graph)

## 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)
nodes(g)
[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)
nodes(gOK)
[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)
nodes(gBUG)
[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
traceback()
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:

setMethod("addNode",
         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,
robert.
ps: sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF8       LC_NUMERIC=C 
LC_TIME=en_US.UTF8        LC_COLLATE=en_US.UTF8
  [5] LC_MONETARY=en_US.UTF8    LC_MESSAGES=en_US.UTF8 
LC_PAPER=en_US.UTF8       LC_NAME=C
  [9] LC_ADDRESS=C              LC_TELEPHONE=C 
LC_MEASUREMENT=en_US.UTF8 LC_IDENTIFICATION=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