R interface: loop edge label plotmath expression gives warning
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
igraph |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Trying to use plotmath (i.e. expressions) with edge labels gives warning messages like the following relating to the labels on loop edges:
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (!is.na(label)) { :
the condition has length > 1 and only the first element will be used
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (!is.na(label)) { :
the condition has length > 1 and only the first element will be used
Some debugging in plot.igraph (see below) revealed that although the labels are a vector of expressions outside the mapply call which invokes the loop function, once you get inside that function the individual label values have become of type language (and of length > 1) rather than of type expression. Therefore a possible fix might be to replace "if (!is.na(label) )" with "if (is.language(label) || !is.na(label))".
To reproduce:
library(igraph)
nodes <- data.frame(
labels <- expression(
nn <- as.character(
edges <- data.frame(
gg <- graph.data.
V(gg)$label <- labels
plot(gg,
options(warn=1)
probs <- c(expression(
str(probs)
E(gg)$label <- probs
plot(gg,
By the way, I am using the phantom("xxxxxx") used in an attempt to shift the labels off the edges - have I missed a better way to do that? (If not, could I submit a request for some kind of position adjustment for edge labels?)
Session transcript below includes debugging:
R version 2.10.1 Patched (2010-02-02 r51093)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(igraph)
> nodes <- data.frame(
+ color=rep(
+ x=c(-1,1),
+ y=c(1,-1))
> labels <- expression(
> nn <- as.character(
> edges <- data.frame(
+ to=c(rev(nn),nn),
+ loop.angle=
+ curved=0.35,
+ lty=rep(1,4),
+ color=rep(
> gg <- graph.data.
> V(gg)$label <- labels
> plot(gg,
> options(warn=1)
> probs <- c(expression(
> str(probs)
expression(
> E(gg)$label <- probs
> plot(gg,
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (!is.na(label)) { :
the condition has length > 1 and only the first element will be used
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (!is.na(label)) { :
the condition has length > 1 and only the first element will be used
> sessionInfo()
R version 2.10.1 Patched (2010-02-02 r51093)
i386-pc-mingw32
locale:
[1] LC_COLLATE=
[2] LC_CTYPE=
[3] LC_MONETARY=
[4] LC_NUMERIC=C
[5] LC_TIME=
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] igraph_0.5.3
>
> library(debug)
Loading required package: mvbutils
Loading required package: tools
Attaching package: 'mvbutils'
The following object(s) are masked _by_ .GlobalEnv :
cd
The following object(s) are masked from package:graphics :
clip
Loading required package: tcltk
Loading Tcl/Tk interface ... done
> mtrace(plot.igraph)
> plot(gg)
D(2)> bp(94) # line 94 is mapply(loop ... call
NULL
D(2)> go()
NULL
Vertices: 2
Edges: 4
Directed: TRUE
Edges:
[0] 'hello' -> 'world'
[1] 'world' -> 'hello'
[2] 'hello' -> 'hello'
[3] 'world' -> 'world'
D(2)> str(loop.labels) # just before mapply(loop ...
expression(
NULL
D(2)> mtrace(loop) # loop is internal function within plot.igraph, so have to mtrace it here
Mode: function Length: 1 Size: 16004
D(2)>
D(26)> str(label) # now inside loop function - note magic transition from expression to language
language phantom("xxxxxxxx") * P[w](O)
NULL
D(26)> length(label) # this is immediate cause of the warning
[1] 3
D(26)> go()
NULL
[1] 1.570796
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (j) TRUE :
the condition has length > 1 and only the first element will be used
D(26)> str(label)
language phantom("xxxxxxxx") * P[x](O)
NULL
D(26)> go()
NULL
[1] 1.570796
Warning in is.na(label) :
is.na() applied to non-(list or vector) of type 'language'
Warning in if (j) TRUE :
the condition has length > 1 and only the first element will be used
NULL
>
Thanks for your detailed report, I've fixed this in revision #1786 (0.6-main) and #1591 (0.5-main).
I've also added a bug for the edge-label positioning: /bugs.launchpad .net/igraph/ +bug/530802
https:/